CakePHP 重定向到另一个网址,但相同的控制器


CakePHP redirect to another url but same controller

我从蛋糕php和mvc和php框架开始,所以我有点困惑。

正如我所看到的,cakephp 允许我路由 url,所以我有一个用于管理的用户控制器,我想知道如何将其重定向到/admin/users/* 而不是/users/*。

我试过这个:

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

但是这使得控制器也在/users 上,我希望/users url 消失,而是使用/admin/users。

谢谢

保存蛋糕路线包括:-

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

在文件末尾,在您的路由之后。

您的路线是正确的。但是要停用"/users"路由,您需要删除默认的 cakephp 路由。删除路由中的以下行.php:

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

更多信息在这里 => http://book.cakephp.org/2.0/en/development/routing.html#disabling-the-default-routes

感谢您的回复。我最终通过使用前缀路由并在用户控制器的索引中抛出 notfoundexception 来管理它。这使得/users 消失了。