Yii中的控制url:controller/action/id to/id [英] Controlling url in Yii: controller/action/id to /id

查看:14
本文介绍了Yii中的控制url:controller/action/id to/id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在 Yii 中以 controller/action/id 格式显示 url 到 /id 吗?此外,一个主要问题是我只需要在特定的控制器/动作上执行此操作.

Can we display url in the format controller/action/id to /id in Yii? Also, one major problem is that I need to do this only on the specific controller/action.

例如:如果我有 /user/post/ujjwal 那么我只需要显示 /ujjwal.当我有 /image/display/ujjwal 时,它可以保持原样吗?

For Instance: If I have /user/post/ujjwal then I need to show /ujjwal only. And when I have /image/display/ujjwal then it can be as it is?

我已经阅读了 Yii 中的 url 管理并理解其中显示的内容.但是我不知道如何根据controller/action来控制url.

I have read the url management in Yii and understand whatever is shown in there. But I dont' know how to control the url based on the controller/action.

任何帮助将不胜感激.

谢谢,乌杰瓦尔

推荐答案

在你的 config/main.php 尝试

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName'=>false,
                        'rules'=>array(
                          'user/post/<user:w+>'=>'<user>', //this should be the very first rule
                           //other rules 
                         ),
            ),
        ),

这篇关于Yii中的控制url:controller/action/id to/id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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