Answer the question
In order to leave comments, you need to log in
Url manager different rules for one controller?
There is a site with such pages.
https://mysite/site/category?id=1&cat=category_1
https://mysite/site/sub?id_sub=1&al=sub_category_5
as you can see they are in the same controller, you need to bring them to this form
https://mysite/ category_1?id=1
https://mysite/sub_category_5?id_sub=5
how to implement it? Need to write your own set of rules? Or is it possible somehow by standard means?
Answer the question
In order to leave comments, you need to log in
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/<id>/<id_sub>' => 'site/category'
]
],
You can try to use the default values in the rules.
More about their use of Default Parameter Values
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'pattern' => 'category_1',
'route' => '/site/category',
'defaults' => ['cat' => 'category_1']
],
[
'pattern' => 'sub_category_5',
'route' => '/site/sub',
'defaults' => ['al' => 'sub_category_5']
],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question