adeade
adeade

Reputation: 317

Yii2 url routing to get a string parameter

I have a url like this

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

I need to get the text my-custom-string-parameter

And I setup the rules like this

'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',
            ),
        ],

This always give me 404 error. What should I do?

Upvotes: 3

Views: 5330

Answers (1)

Don Vincent
Don Vincent

Reputation: 476

replace 'category/<url:>' => 'category/view',, with 'category/<id:\w+>' => 'category/view'

Routing to View need an id and to use a string use w+ not url:

Upvotes: 6

Related Questions