Controlling url in Yii: controller/action/id to /id

前端 未结 3 666
滥情空心
滥情空心 2021-01-22 13:02

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/

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-22 13:43

    In my opinion you can not map one customized URL to two or more URL path or action. Like when someone access /my_username the will be redirected to /user/post/ujjwal or /image/display/ujjwal. The application will be confused because of this pattern/rules.

    So I recommend you to change the /image/display/ujjwal to another pattern/rules. Like /my_username/image

    I use username as the query string for selected username.

    'components'=>array(
    
                .....
    
                'urlManager'=>array(
                'urlFormat'=>'path',
                'rules'=>array(
                    ''=>'user/post',
                    '/display'=>'image/display',
                    '/'=>'/view',
                    '//'=>'/',
                    '/'=>'/',
                ),
            ),
    
                ....
    

    Someone has asked this similar question before: How to specify a SEO friendly url like twitter www.twitter.com/ using YII framework

提交回复
热议问题