M
M
metallix2016-06-01 09:11:06
Yii
metallix, 2016-06-01 09:11:06

Yii2 - how to set url rule correctly?

Hello, and actually - a subject.
There is a rule -

<categories/<id:\d+>/<slug:\w+> => 'categories/index'
, which works well for links like "example.com/categories/5/sport".
But if the 'slug' parameter consists of several parts, eg. 'music-and-movies', then the rule fails and redirects to a 404 page. But if in 'slug' the hyphen is replaced with an underscore, then everything works. What is the problem?
After all, as far as I understood from the documentation, '\w+' should understand hyphens too

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-06-01
@metallix

If you are not friends with the regular season, do not use or learn. It can be like this:'categories/<id>/<slug>' => 'categories/index'

M
matperez, 2016-06-01
@matperez

add a dash to the regular expression. something like slug:[\w-]+ or slug:[\w\-]+

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question