url management in Yii 2

帅比萌擦擦* 提交于 2019-12-09 02:56:53

问题


I have this url

http://example.com/index.php/controller_name/action_name?queryString=123

This url is working fine but when I am trying to use the queryString like in the old version of Yii

http://example.com/index.php/controller_name/action_name/queryString/123

I get an "unable to solve request" error.

I 've already enable prettyurl in my config file and the following url is working

 http://example.com/index.php/controller_name/action_name.

My config looks like :

'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
        ],
    ],

What am I missing?


回答1:


Unfortunately this feature didn't migrate to Yii2, you can still define such rules manually

'books/view/queryString/<queryString:\w+>' => 'books/view',

Link on github with this issue

Because of many client API and Oauth servers don't work without encode

Sam Dark answer



来源:https://stackoverflow.com/questions/22963353/url-management-in-yii-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!