Yii2 url 路由获取字符串参数
Yii2 url routing to get a string parameter
我有一个url这样的
http://localhost/yii2/category/my-custom-string-parameter
我需要获取文本 我的自定义字符串参数
然后我设置了这样的规则
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'category/<url:>' => 'category/view',
),
],
这总是给我 404 错误。
我该怎么办?
将 'category/<url:>' => 'category/view',,
替换为 'category/<id:\w+>' => 'category/view'
路由到视图需要一个 id 并且要使用字符串使用 w+ 而不是 url:
我有一个url这样的
http://localhost/yii2/category/my-custom-string-parameter
我需要获取文本 我的自定义字符串参数
然后我设置了这样的规则
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'category/<url:>' => 'category/view',
),
],
这总是给我 404 错误。 我该怎么办?
将 'category/<url:>' => 'category/view',,
替换为 'category/<id:\w+>' => 'category/view'
路由到视图需要一个 id 并且要使用字符串使用 w+ 而不是 url: