Yii2 url路由获取字符串参数

adeade

我有一个这样的网址

http:// localhost / yii2 / category / my-custom-string-parameter

我需要获取文本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'

路由到View需要一个id并使用w +而不是url来使用字符串:

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章