CakePHP管理员和网站路由器

时间:2015-01-07 19:16:26

标签: php cakephp routing

我正在学习CakePHP,而我正在建立一个CMS,但我似乎无法使我的路由器正确。

每个网址都应该使用WebsiteController的索引操作,除了" admin"

/ admin有效,但当我去/ foobar它要求FoobarController

Router::connect("/admin/:controller/:action", 
    array("controller" => "admin")
);
Router::connect("/", 
    array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*", 
    array("controller" => "website", "action" => "index"), 
    array("pass" => array("slug"), "slug" => '(?!admin)')
);

2 个答案:

答案 0 :(得分:1)

我认为问题是"slug" => '(?!admin)'。你无论如何都不需要它,因为以/ admin开头的网址已经被你的第一条路线捕获了。

其他问题,以下路线没有意义:

Router::connect("/admin/:controller/:action", 
   array("controller" => "admin")
);`

它基本上告诉管理员控制器和foobar控制器处理/ admin / foobar url。

试试这个:

Router::connect("/admin",
    array("controller" => "admin", "action" => "index")
);
Router::connect("/admin/:action",
    array("controller" => "admin")
);
Router::connect("/",
    array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*",
    array("controller" => "website", "action" => "index"),
    array("pass" => array("slug"))
);

答案 1 :(得分:0)

所以,我明白了。

删除:

Router::connect("/admin/:action",
    array("controller" => "admin")
);
Router::connect("/",
    array("controller" => "website", "action" => "index")
);

并补充说:

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

Router::connect("/:slug",
    array("controller" => "website", "action" => "index"),
    array("pass" => array("slug"))
);

特别感谢PGBI