A
A
alex5e2017-05-10 11:54:44
Yii
alex5e, 2017-05-10 11:54:44

How to generate a slug routing rule in Yii2 module?

There is a blog module.
There is a rule that blog/article1 should open an article
'blog/<page:\w+(-\w+)*>'=>'blog/default/view'

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

'rules' => [
     'blog/<page:\w+(-\w+)*>'=>'blog/default/view' // Вот это правило
     '<controller:\w+(-\w+)*>/<id:\d+>' => '<controller>/view',
     '<controller:\w+(-\w+)*>/<action:\w+(-\w+)*>' => '<controller>/<action>',
     '<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
     '<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
     '<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
]

I don’t get into Action, I get 404th
Prompt, where did I go wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex5e, 2017-05-10
@alex5e

The problem turned out to be a redirect without a slash to a page with a slash at the end

M
Maxim Timofeev, 2017-05-10
@webinar

Should work. See debug, I'm sure that some method is already throwing an error in the controller, give the code of your actionView

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question