Yii-在URL中隐藏模块名称 [英] Yii - Hiding module name in URL

查看:61
本文介绍了Yii-在URL中隐藏模块名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的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.

因此,如果您希望任何控制器/操作转到确切网址模块/控制器/操作,则可以使用第一个示例.例如,如果您希望控制器/操作站点/测试进入模块/控制器/操作,则可以使用上面的第一个示例

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆