在Yii中嵌套控制器URL结构


nested controllers URL structure in Yii

我想知道在Yii中嵌套URL结构的最佳方法是什么我有一个网站的结构像下面的

/index
/dashboard (dashboard controller, index action)
/dashboard/profile (profile controller, index action)
/dashboard/profile/view (profile controller, view action)
/dashboard/profile/update (profile controller, update action)
/dashboard/stats (stats controller, index action)

等等…

基本上/dashboard有它自己的控制器,默认情况下会使用Index动作然而,我想在/dashboard下嵌套其他控制器,例如/dashboard/profile然而,/profile控制器不是一个动作,它应该是一个控制器,反过来可以有自己的动作。如仪表板/档案/视图

这可行吗?如果有,实现这种结构的最佳方式是什么?

如果您已经按照Yii网站上的教程在应用程序中隐藏index.php:

'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    'caseSensitive' => false,
    'rules' => array(
        'dashboard/<controller:'w+>/<action:'w+>' => '/dashboard/<controller>/<action>',
        'dashboard/<controller:'w+>' => '/dashboard/<controller>/index',
        '<controller:'w+>/<action:'w+>/<id:'d+>' => '<controller>/<action>',
        '<controller:'w+>/<action:'w+>' => '<controller>/<action>',
        '<controller:'w+>/' => '<controller>/index',
        ...

还有一种可能没有提到的方法。昨天我会回答"使用模块",但今天我学习(和测试),它是足够的添加子文件夹到文件夹"控制器"answers"视图"。例如,文件夹:"/controllers/dashboard"和文件"ProfileController.php"将启用URL: "myproject.com/dashboard/profile/action",视图将在文件夹"views/dashboard"中搜索。

但是有一个问题,你不能使用URL: "myproject.com/dashboard/"作为"dashboard"只是一个文件夹名称。所以你可能不得不使用模块。

YouTube::Kurt Clement - Yii - UrlManager