【问题标题】:Admin index route ignored w/ CakePHP 2.1使用 CakePHP 2.1 忽略管理索引路由
【发布时间】:2017-09-08 14:32:55
【问题描述】:

我正在开发一个 CakePHP 2.1 项目,但我遇到了关于管理面板“主页”的问题。

当我进入:mysite.com/admin 我有一条消息告诉我“找不到 AdminController”。

我在 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));

【问题讨论】:

  • 可能定义了更多的路由,即可能存在冲突的路由。
  • 我用 routes.php 的内容编辑了我的帖子。

标签: cakephp routes cakephp-2.1


【解决方案1】:

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

require CAKE . 'Config' . DS . 'routes.php';

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

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

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

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

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

【讨论】:

  • 如果我知道它就这么简单...我对 CakePHP 完全陌生,所以我没有检查默认代码行。谢谢!
猜你喜欢
  • 2013-05-29
  • 2014-06-21
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
相关资源
最近更新 更多