Search code examples
phpyiiyii-url-manager

Yii URL manager routing additional variables not finding a route?


My current url manager:

'urlManager'=>array(
            'showScriptName'=>false,
            'urlFormat'=>'path',
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                'rest/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                'rest/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),

With regards to the rest route

http://htt.local/rest/v1/show/2916

works!!

http://htt.local/rest/v1/candle/2916/from/2015-12-23
Unable to resolve request

Solution

  • Your url manager should be like this:

    'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                'rest/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    
                /* Add this line */
                'rest/<controller:\w+>/<action:\w+>/<id:\d+>/from/<date>'=>'<controller>/<action>',
                /*  */
    
                'rest/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),