Answer the question
In order to leave comments, you need to log in
How to properly write UrlManager in YII2?
Question on urlManager Yii2 It is
necessary to make a url from the root (site.ru/zdanie-iz-cataloga-s-takim-nazvaniem), in connection with the transfer of the site to Yii2
What should be written in the config?
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'что-то с alias или суффиксом' => 'catalog/views/',
],
]
<a href="<?=Url::toRoute('view','$model->alias') ?>"><?=$model->name_zdanie?></a>
, Answer the question
In order to leave comments, you need to log in
Rules are processed one at a time from top to bottom. Accordingly, the first rule '' => 'site/index'
cannot be set. It will always work. It needs to be at the very end.
I understand that there is a controller with a route catalog/view
and it takes a parameter alias
. If so, then the rule is:
Well, generation, respectively:
<a href="<?=Url::toRoute(['/catalog/view', 'alias' => $model->alias]) ?>"><?= Html::encode($model->name_zdanie)?></a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question