蛋糕路由表显然得到了补充

时间:2019-05-14 11:23:06

标签: php cakephp routing

我继承了在Cake框架上构建的代码体,并且难以理解其路由。我知道Cake体现了各种约定,这意味着做出了一些神奇的假设,也许这就是我的困难。我不是蛋糕专家。

我想要实现的是/路由以及其他各种路由的处理程序。因此,路由代码如下所示(为简便起见,省略了注释):

    error_log('Route(((');
    Router::connect('/',array('controller' => 'users', 'action' => 'showoffpage'));
    Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
    Router::connect('/admin', array('controller' => 'users', 'action' => 'login', 'admin' => true));
    Router::connect('/:slug',array('controller' => 'users', 'action' => 'profile'), array('pass' => array('slug')));
    CakePlugin::routes();
    error_log(')))Route -- ' . json_encode(Router::$routes));

,遇到此情况时,将输出以下内容:

[Tue May 14 19:11:19 2019] Route(((
[Tue May 14 19:11:19 2019] )))Route -- [{"keys":[],"options":[],"defaults":{"controller":"users","action":"showoffpage","plugin":null},"template":"\/"},{"keys":[],"options":[],"defaults":{"controller":"users","action":"logout","plugin":null},"template":"\/logout"},{"keys":[],"options":[],"defaults":{"controller":"users","action":"login","admin":true,"prefix":"admin","plugin":null},"template":"\/admin"},{"keys":[],"options":{"pass":["slug"]},"defaults":{"controller":"users","action":"profile","plugin":null},"template":"\/:slug"}]
[Tue May 14 19:11:19 2019] 106.70.102.45:51080 [302]: /
[Tue May 14 19:11:19 2019] Route(((
[Tue May 14 19:11:19 2019] )))Route -- [{"keys":[],"options":[],"defaults":{"controller":"users","action":"showoffpage","plugin":null},"template":"\/"},{"keys":[],"options":[],"defaults":{"controller":"users","action":"logout","plugin":null},"template":"\/logout"},{"keys":[],"options":[],"defaults":{"controller":"users","action":"login","admin":true,"prefix":"admin","plugin":null},"template":"\/admin"},{"keys":[],"options":{"pass":["slug"]},"defaults":{"controller":"users","action":"profile","plugin":null},"template":"\/:slug"}]
[Tue May 14 19:11:19 2019] PROFILE:pages
[Tue May 14 19:11:19 2019] 106.70.102.45:51082 [200]: /pages

也就是说,即使路由表仅包含此处代码中设置的四个条目,空路由也会立即“重写”为/pages。然后将匹配发送到UsersController::profile('pages')(因此,诊断PROFILE:pages输出)而不是UsersController::showoffpage()UsersController::showoffpage()中有调试程序,但从不输出。显然,我在源中搜索了单词pages的出现,但有100个。 Cake会做些什么来使其重写路线,我该如何阻止它?

1 个答案:

答案 0 :(得分:0)

感谢Salines的评论,因为它促使我​​寻找正确的位置。方法AppController::_checkAuth()正在执行重定向,因为我的新路由不在白名单中。