1

I was wondering what's the best way to have a nested URL structure in Yii I have a website with a structure like the following

/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)

and so on...

Basically /dashboard has it's own controller and by default will use the Index action however I would like to nest other controllers under /dashboard, e.g. /dashboard/profile however, the /profile controller is not an action, it should be a controller which in turn can have it's own actions. e.g. /dashboard/profile/view

is this doable? if yes, what would be the best way to achieve such a structure?

4

2 に答える 2

3

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',

        ...
于 2013-06-03T14:05:54.493 に答える
2

おそらく言及されていないもう1つの方法があります。昨日は「モジュールを使用する」と答えていましたが、今日はサブフォルダーをフォルダー「コントローラー」と「ビュー」に追加するだけで十分であることを学びました(そしてテストしました)。たとえば、フォルダ: "/controllers/dashboard" とファイル "ProfileController.php" を指定すると、URL: "myproject.com/dashboard/profile/action" が有効になり、ビューはフォルダ "views/dashboard" で検索されます。

ただし、「dashboard」はフォルダ名のみであるため、URL:「myproject.com/dashboard/」を使用できないという問題があります。したがって、おそらくモジュールを使用する必要があります。

YouTube::Kurt Clement - Yii - UrlManager

于 2014-07-06T15:06:47.347 に答える