Url Manager

Hi,

In yii1 the highlighted rule would be caught by the url "http://–/detail/xpto_e45", however in yii2 ithis url is never caught.

Anybody knows the reason? Or what I’m doing wrong?

‘urlManager’ => array(

        'class' => 'yii\web\UrlManager', //Set class


        'enablePrettyUrl' => true, //new showScriptName = false,


        'showScriptName' => false,          


        'rules' => array(             	


            'entrydetail/[\w,-]*_e<key>' => 'discount/detail',


            'entry/detail/queryString/<queryString:\w+>' => 'entry/show',


            '<controller:\w+>/<id:\d+>' => '<controller>/view',


            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',


            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',


            [b]'detail/[\w,-]*_e<key>' => 'entry/detail',[/b]


            ),


    ),

Thank you

Can’t help too much, but when I was getting going on Yii 1.x I had similar problems and a few time it was other rules prior firing that prevented the rule from being hit. Try moving the rule to the top and see if it works.

Sandy

Rule looks OK. Try moving it upper.

It doesn’t work.

Here’s my urlManager configuration:




'urlManager' => [

            'class' => 'yii\web\UrlManager',

            'enablePrettyUrl' => true, 

            'showScriptName' => false,          

            'rules' => [

                'detail/[\w,-]*_e<key>' => 'entry/detail',

                '<controller:\w+>/<id:\d+>' => '<controller>/view',

                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',

                ],

        ],

I’m calling this url: http://localhost/tes...ail/sgsdggs_e10 and I’m receiving a 404 with [size=“2”]"[color="#222222"][font=“Roboto”]Unable to resolve the request “detail/sgsdggs_e10”.[/font][/color][/size]

[size="2"] [/size]

[size="2"][font="Roboto"][color="#222222"]The debug log shows the following:[/color][/font]

[/size]

  • [font="Roboto"][color="#222222"][size="2"][color="#333333"]Request parsed with URL rule: <controller:\w+>/<action:\w+>[/color][/size][/color][/font]
  • [font=“Roboto”][color="#222222"][size=“2”][color="#333333"]Route requested: ‘detail/sgsdggs_e10’[/color][/size][/color][/font]
  • [font=“Roboto”][color="#222222"][size=“2”][color="#333333"]exception ‘yii\base\InvalidRouteException’ with message ‘Unable to resolve the request “detail/sgsdggs_e10”.’ in /Applications/AMPPS/www/test/vendor/yiisoft/yii2/base/Module.php:429[/color][/size][/color][/font]

Are you sure rules are applied i.e. in correct config and that config is correct?

I suppose so, because if I comment this "[color="#008800"]’<controller:\w+>/<action:\w+>’[/color] [color="#666600"]=>[/color] [color="#008800"]’<controller>/<action>’[/color][color="#666600"],"[/color]


'urlManager' => [


            'class' => 'yii\web\UrlManager', 


            'enablePrettyUrl' => true, 


            'showScriptName' => false,          


            'rules' => [


                'detail/[\w,-]*_e<key>' => 'entry/detail',


                '<controller:\w+>/<id:\d+>' => '<controller>/view',


                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',


                 //'<controller:\w+>/<action:\w+>' => '<controller>/<action>',


                ],


        ],




[color="#666600"]it will give me an error saying that it found no valid rule to route.[/color]

from what I’ve seen by looking at the yii source code it’s compiling my rule into [font=“Times”][size=“2”] #^detail/\\[\w,-\]\_e$#u[/size][/font]

[font="Times"][size="2"][b]

[/b][/size][/font]

[font="Times"][size="2"]If I inject this code at yii/web/UrManager:230[/size][/font]

[font=“Times”][size=“2”] $rule->pattern = ‘/detail\/[\w,-]_e/’;[/size][/font]

[font="Times"] [/font]

[font="Times"][size="2"]It works as it should.

[/size][/font][font="Times"][size="2"][b]

[/b][/size][/font]