S
S
Sergey Beloventsev2016-06-15 12:57:33
Yii
Sergey Beloventsev, 2016-06-15 12:57:33

How to defeat URLmanager again?

I have a question here are the rules

'serials/<slug:\w*>' =>  'serial/category/list',
    'serials/<id>'   =>  'serial/category/oneserial',

write links like this
Yii::$app->urlManager->createUrl(['/serial/category/oneserial','id'=>$model->slug_serial]) //ссылка формируется такая /serials/serial-nazvanie-seriala
     Yii::$app->urlManager->createUrl(['/serial/category/list','slug'=>$ct->slug_category])//ссылка формируется такая /serials/сategory

but if you add a dash to /serials/nazvanie-category for example, then in the address bar I get serials?slug=nazvanie-category tried to solve it like this
'serials/<slug:\w*>' =>  'serial/category/list',
    'serials/<slug:[\w_\-]+>' =>  'serial/category/list',
    'serials/<id>'   =>  'serial/category/oneserial',

now here /serials/nazvanie-category it turns out well, but this address /serials/serial-nazvanie-seriala now also uses the second rule parses serial/category/list to this address, which throws it on the main page and honestly 1 I don’t understand why and 2 how to fix it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
polar-bear, 2016-06-15
@Sergalas

You are trying to open both the category and the series itself, in the same 'serials' prefix. There are no problems when creating a url, but when parsing, yii takes the first matching rule.
Create a better class of rules url Creating Rule Classes , and search the database, there is a series forwarding on the series, if not, check the category and if it exists on the category.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question