CakePHP 2.1 忽略管理索引路由

Admin index route ignored w/ CakePHP 2.1

我正在处理一个 CakePHP 2.1 项目,我有一个关于管理面板 "homepage" 的问题。

当我输入:mysite.com/admin 我有一条消息告诉我 "AdminController cannot be found".

我在 config/routes 中声明了这条路线。php :

Router::connect('/admin', array('controller' => 'mycontroller', 'action' => 'index', 'admin' => true));

当我输入 mysite.com/admin/mycontroller 作为 URI 时,它起作用了。 你有什么想法吗?

提前致谢。

编辑 |我的 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/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));

正如所怀疑的那样,存在冲突路由,即由核心提供的 the default routes,您通过

将其包括在内
require CAKE . 'Config' . DS . 'routes.php';

在定义您的 /admin 路线之前。

默认值连接各种可以隐藏您的路由,例如:

Router::connect("/{$prefix}/:controller", $indexParams);

Router::connect('/:controller', array('action' => 'index'));

长话短说,顺序很重要,将您的路由定义移动到包含默认路由的上方。