Yii 2 中的 url 管理 [英] url management in Yii 2
本文介绍了Yii 2 中的 url 管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个网址
http://example.com/index.php/controller_name/action_name?queryString=123
这个 url 工作正常,但是当我尝试使用旧版本的 Yii 中的 queryString
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.
我已经在我的配置文件中启用了prettyurl,并且下面的url正在工作
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>',
],
],
我错过了什么?
推荐答案
很遗憾这个特性没有迁移到 Yii2,你仍然可以手动定义这样的规则
Unfortunately this feature didn't migrate to Yii2, you can still define such rules manually
'books/view/queryString/<queryString:\w+>' => 'books/view',
因为许多客户端 API 和 Oauth 服务器在没有编码的情况下无法工作
Because of many client API and Oauth servers don't work without encode
这篇关于Yii 2 中的 url 管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文