Yii - 从 URL 中删除“索引" [英] Yii - Remove 'index' from URL
问题描述
如何从 http://localhost/dashboard/index/create
我的 urlManager
设置如下:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
这给了我像这样的干净 URL http://localhost/dashboard
其中 dashboard
是一个带有名为 indexController
的默认控制器的模块.
And this gives me clean URLs like this http://localhost/dashboard
where dashboard
is a module with a default controller named indexController
.
现在,我遇到的问题是,如果不先放入 index
就无法访问模块控制器的其他操作,例如,如果我想在 中调用
,我总是要说actionCreate
indexControllerhttp://localhost/dashboard/index/create
.
Now, the problem I am having is that I cannot access other actions of the module controller without first putting index
e.g If I want to call actionCreate
inside indexController
, I always have to say http://localhost/dashboard/index/create
.
有什么办法可以摆脱 index
并像这样调用它:http://localhost/dashboard/create
?
Is there any way I can get rid of index
and just call it like this: http://localhost/dashboard/create
?
这是我的模块在 main.php
中的配置方式:
This is how my module is configured in main.php
:
'modules' => array(
...
'dashboard' => array(
'defaultController' => 'index'
),
...
),
提前谢谢你:-)
推荐答案
尝试这样排列你的数组(把仪表盘开头的那行放在你的 urlManager 组件下):
Try arranging your array like this (put the line beginning with dashboard under your urlManager component):
array(
...
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
'dashboard/<action:\w+>' => 'dashboard/index/<action>'
),
),
),
);
这篇关于Yii - 从 URL 中删除“索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!