Admin index route ignored w/ CakePHP 2.1 - cakephp

I'm working on a CakePHP 2.1 project and I have an issue concerning the "homepage" for admin panel.
When I enter : mysite.com/admin
I have a message telling me "AdminController cannot be found".
I declared this route in config/routes.php :
Router::connect('/admin', array('controller' => 'mycontroller', 'action' => 'index', 'admin' => true));
And when I enter mysite.com/admin/mycontroller as URI, it works.
Do you have an idea ?
Thank you in advance.
Edit | My routes.php file :`
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/View/Pages/home.ctp)...
*/
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
* Load all plugin routes. See the CakePlugin documentation on
* how to customize the loading of plugin routes.
*/
CakePlugin::routes();
/**
* Load the CakePHP default routes. Only remove this if you do not want to use
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
// Custom routes
Router::connect('/admin', array('controller' => 'jobapplications', 'action' => 'index', 'admin' => true));

As suspected, there are conflicting routes, namely the default routes provided by the core, which you are including via
require CAKE . 'Config' . DS . 'routes.php';
before defining your /admin route.
The defaults connect various routes that can cloak yours, for example:
Router::connect("/{$prefix}/:controller", $indexParams);
or
Router::connect('/:controller', array('action' => 'index'));
Long story short, order matters, move your route definition above the inclusion of the default routes.

Related

Router failed CakePHP 3.x

http://localhost/index
but connect to http://localhost/abc...xyz => THIS WILL BE ERROR PAGE SYSTEM
after, i want connect to http://localhost/index
Unable to understand . Please describe properly.
You may update Config/routes.php
Router::scope('/', function (RouteBuilder $routes) {
/**
* Here, we are connecting '/' (base path) to a controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/index.ctp)...
*/
$routes->connect('/index', ['controller' => 'Pages', 'action' => 'index']);
}

How to access plugin in cakephp

I am new in cakephp, I want to call the plugin via the URL. Here is URL of
http://testproject.local/PluginName/ControllerName/ActionName
When I Run this URL at that time I found "Missing Controller" error.
Missing Controller
Error: <ControllerName>Controller could not be found.
Error: Create the class <ControllerName>Controller below in file: `app/Controller/<ControllerName>Controller.php`
It's showing me
`Exception Attributes: array ( 'class' => 'PracticeFusionController', 'plugin' => NULL, )`
Here is my routes.php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
Router::connect('/Pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/gods/:action/*', array('plugin' => 'nova', 'controller' => 'gods'));
Router::connect('/gods', array('plugin' => 'nova', 'controller' => 'gods'));
Router::parseExtensions('json', 'xml');
Router::mapResources('events');
Router::connect('/<pluginName>', array('plugin' => '<pluginName>', 'controller' => '<ControllerName>'));
You can only load/open Plugin routes if you actually loaded the plugin in your project's bootstrap. You don't need to include a plugin route in your core app's routes.php. If you want to add plugin specific routes, you can load the plugin specific routes file, using the routes option. Note that by default all /plugin/controller/action routes are already routed properly, you don't need a separate routes file for that.
So, in your core app's app/Config/bootstrap.php, add:
CakePlugin::load('YourPlugin', array('routes' = true));
The routes from your plugin's Config/routes.php will then be loaded and can be used.
More details on this can also be found in the documentation.
If above solutions does not works, please load plugin like CakePlugin::load('YourPlugin', array('routes' => true)); Please note array passed is : array('routes' => true)

Problems with routes and CakePHP 2.2.2

I have installed CakePHP on windows over II7 and i am having problems with the routes.
I have created a Model, a Controller and a View for Users.
When i try to access the index view, i do it like this without any problem:
http://myhost/cakephp/users/
But, when I try to add a new user, the view doesn't load properly:
http://myhost/cakephp/users/add/
It shows this error:
Error: AddController could not be found.
Error: Create the class AddController below in file: app\Controller\AddController.php
In order to make it work, i have to do this in app/Config/routes.php:
Router::connect('/users/add', array('controller' => 'users', 'action' => 'add'));
But that wouldn't be necessary if it worked well.
Neither the delete or view views load.
What's going on? How can i detect the problem?
Thanks.
EDIT
Content of routes.php:
Router::connect('/', array(
'controller' => 'pages', 'action' => 'display', 'home'
));
Router::connect('/pages/*', array(
'controller' => 'pages', 'action' => 'display'
));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
Ok, it seems i have solved it. It was all because of adding a routing prefix using cake bake console... I had to comment this line at core.php
Configure::write('Routing.prefixes', array('users'));

cakephp default controller/action routing with pagination breaks with named parameters

I have default routing rule set:
Router::connect('/', array('controller' => 'photos', 'action' => 'index'));
when i go to
http://url.com/photos/index/page:1/limit:10/direction:desc/
everything works fine but it breaks when i go to
http://url.com/page:1/limit:10/direction:desc/
First, you need to tell your route to parse after the /:
Router::connect('/*', array('controller' => 'photos', 'action' => 'index'));
Then, connect the named parameters:
Router::connectNamed(false, array('defaults' => true));
You can also set them within your route, if you prefer. More information on connecting named parameters here: http://book.cakephp.org/2.0/en/development/routing.html#controlling-named-parameters

How can I redirect the default home page to another page in CakePHP?

I need to redirect the default CakePHP home page / or (/pages/home) to /users/dashboard page
I tried
Router::connect('/', array('controller' => 'users', 'action' => 'dashboard'));
and
Router::connect('/pages/home', array('controller' => 'users', 'action' => 'dashboard'));
But both are not working
You should be able to do this by simply replacing this part of app/config/routes.php:
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/views/pages/home.ctp)...
*/
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
.. with something like this:
/**
* Here, we are connecting '/' (base path) to controller called 'Users' and
* its action called 'dashboard' (ie. /users/dashboard)...
*/
Router::connect('/', array('controller' => 'users', 'action' => 'dashboard'));
I sense a slight misunderstanding of the topic when you try to map from '/pages/home' to your dashboard. '/pages/home' only seems like the home page because there exists a route for that. If you want to change the homepage, you need to change the existing Router::connect('/', ...) rule. If you create a new rule for '/', underneath, it won't be executed as CakePHP will match the first route it finds.
your first attempt
Router::connect('/', array('controller' => 'users', 'action' => 'dashboard'));
Is the correct way to do it. If you are still having problems then there must be another issue.
What error do you see?

Resources