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
before defining your
/admin
route.The defaults connect various routes that can cloak yours, for example:
or
Long story short, order matters, move your route definition above the inclusion of the default routes.