Yii - 在 URL 中隐藏模块名称 [英] Yii - Hiding module name in URL
问题描述
我目前的网址结构如下:
My present URL structure is as below:
http://www.mydomain.com/module/controller/action
我需要隐藏 URL 的模块部分.有什么办法可以做到吗?
I need to hide the module section of the URL. Is there any way this can be done?
谢谢.
推荐答案
指向 URL http://www.mydomain.com/customer/login 到模块,在 urlManager 下的您的配置 (protected/config/main.php) 中:
To point the URL http://www.mydomain.com/customer/login to the module, in you config (protected/config/main.php) under urlManager:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'customer/login' => 'module/controller/action',
'<controller:w+>/<id:d+>'=>'<controller>/view',
'<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
'<controller:w+>/<action:w+>'=>'<controller>/<action>',
),
),
要使任何控制器操作转到模块/控制器/操作(如下所述),您可以使用:
To make any controller action go to module/controller/action (as discussed below) you can use:
'<controller:w+>/<action:w+>'=>'module/controller/action',
或
'<controller:w+>/<action:w+>'=>'module/<controller:w+>/<action:w+>',
取决于值的控制器/动作部分(在 => 的右侧)是设置值还是变量.
Depending on whether the controller/action part of the value (on the right hand side of the =>) is a set value, or a variable.
因此,如果您希望任何控制器/操作转到精确 url 模块/控制器/操作,您可以使用第一个示例.例如,如果您希望控制器/操作 site/test 转到 module/controller/action,您将使用上面的第一个示例
So if you want any controller/action to go to the exact url module/controller/action, you would use the first example. For example if you want the controller/action site/test to go to module/controller/action, you would use the first example above
如果您希望任何控制器/操作转到动态控制器/操作,请使用第二个.例如,如果您希望控制器/操作 site/test 转到 module/site/test,则可以使用上面的第二个示例
If you want any controller/action to go to a dynamic controller/action you use the second. For example, if you want the controller/action site/test to go to module/site/test, you would use the second example above
这个新规则必须高于 3 个默认的 Yii 规则,因为它们被读取并且从上到下并且只匹配它找到的第一条规则
This new rule must be above the 3 default Yii rules as they are read and top to bottom and match the first rule it finds only
这篇关于Yii - 在 URL 中隐藏模块名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!