我正在开发CakePHP 3.3
我有一些名为
的仪表板控制器DashboardUsersController.php,
DashboardBusinessesController.php,
DashboardCustomersController.php,
etc
我想要像
那样映射网址http://example.com/dashboard/users/view/param1/param2
这将调用DashboardUsersController.php
类和view
函数,param1
和param2
作为参数。
简而言之,我想将网址http://example.com/dashboard-users/view/param
更改为http://example.com/dashboard/users/view/param
这种类型的映射只有在域后存在仪表板时才会完成,否则它将像默认情况一样工作,如访问http://example.com/users/view/param1
时会调用UsersController.php
到目前为止我做了什么?
因为,我是CakePHP和路由的新手,我不知道从哪里开始,因此到目前为止什么也没做。我需要你的帮助。
答案 0 :(得分:4)
我认为你需要的是前缀。使用前缀仪表板烘焙控制器模型。
在 routes.php
中使用此功能use Cake\Routing\Route\DashedRoute;
Router::prefix('dashboard', function ($routes) {
// All routes here will be prefixed with `/dashboard
$routes->fallbacks(DashedRoute::class);
});
从控制器中删除该仪表板部件或从表名中删除仪表板,并使用--prefix重新绑定所有内容。
bin / cake bake all --prefix dashboard
这些链接可以帮助您
https://book.cakephp.org/3.0/en/development/routing.html#prefix-routing