In the rules, urlManager prescribed:

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

I generate URL:

 $this->createUrl('article/tag', ['id' => $model->id, 'name' => $model->name]); //$model->id=1; $model->name='newname' 

I expect the following URL: http://domain.ru/article/tag/1/newname
But I get this: http://domain.ru/article/tag/1/?name=newname

It seems that the second rule is simply not involved.
I tried to remove the first rule, and the URL was formed as it should, but on pages with a URL without the name parameter (for example http://domain.ru/article/tag/1 ), if I want to get access to $_GET['id'] error crashes. Undefined index: id . In short, links only work when there are 2 parameters.

Closed due to the fact that off-topic participants are Visman , aleksandr barakin , user194374, Bald , pavel 2 Sep '16 at 9:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Visman, aleksandr barakin, Community Spirit, Bald, pavel
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Is there any other rule before this? In case the router finds a more or less suitable match, it stops searching. - etki
  • @Etki thanks, there was the same rule before it, only without the name parameter - Jeque

1 answer 1

Solved the problem by placing the rules in reverse order.