您好我想在yii2中制作这样的网址 example.com/pagename
example.com/folder1/pagename
example.com/folder1/folder2/pagename
我的代码
路径: - site / pages / folder1 / folder2 /
在main-local.php
中添加'< view >' => 'site/pages',
'folder1/< view >' => 'site/folder1',
“文件夹2 /&LT;查看&gt;' =&GT; 'site / folder1 / folder2',
在sitecontroller我添加第一个是工作但第二个不工作404错误
'pages' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages',
],
'folder1' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages/folder1',
],
'folder2' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages/folder1/folder2',
],
有什么建议吗?
答案 0 :(得分:0)
我用过像你这样的方法我希望它能帮到你。但我没有测试folder2。所以你也可以测试并发送给我结果。:)
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<folder:\w+>/<controller:\w+>/<action:\w+>' => '<folder>/<controller>/<action>',
),
]
]