Answer the question
In order to leave comments, you need to log in
How to generate friendlyUrl for link in Yii2?
I am learning yii2 and faced the problem of creating CNC. As I understand it, in urlManager, you can specify the rules by which the link is parsed into parameters and passed in acc. action, but I have figured out how to get the reverse process. The /helper/url class makes links like "/blog?category=other", not "/blog/other".
My config:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<action:>' => 'site/<action>',
'<action:[\w\-]+>/<category:[\w\-]+>' => 'site/<action>',
],
],
Answer the question
In order to leave comments, you need to log in
Solved the problem myself.
'rules' => [
'<action:(contact|about)>' => 'site/<action>',
'blog/<category>/<post>'=>'site/post',
'blog/<category>'=>'site/blog',
'blog'=>'site/blog',
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question