Answer the question
In order to leave comments, you need to log in
How to make a rule for url?
Good afternoon, there is an address of this kind namesite.com/catalog/1?brand=1
I want to make that there was such an address namesite.com/catalog/1/brand-1 (you need to remove "?=")
I wrote in the urlManager rules:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'catalog/<id:.+>/brand/<brand:[\w-]+>' => 'cat/view',
'catalog/<id:.+>' => 'cat/view',
'catalog' => 'cat/view',
'brand/<id:.+>' => 'brnd/view',
'product/<id:.+>' => 'prod/view',
],
],
<?= Html::a($b->name, ['catalog/'.$model->id.'', 'brand' => $b->id]) ?>
Answer the question
In order to leave comments, you need to log in
'default/<id:\d+>/brand-<brand:\d+>' => 'default/index',
'default/<id:\d+>' => 'default/index',
'default' => 'default/index',
echo Html::a('test', ['default/index', 'id' => $id, 'brand' => $brand])
echo Html::a('test', ['default/index', 'id' => $id])
echo Html::a('test', ['default/index'])
http://site.loc/default/index/3/brand-2
http://site.loc/default/index/3
http://site.loc/default/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question