S
S
slip312014-05-01 15:13:11
Yii
slip31, 2014-05-01 15:13:11

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/', 
            ],
        ]

And in the CatalogController controller?
<a href="<?=Url::toRoute('view','$model->alias') ?>"><?=$model->name_zdanie?></a>
,
so that it works out normally /
Is there something that, by the .html suffix, intercepts and sends it to the right controller?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Makarov, 2014-05-01
@slip31

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/viewand 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>

S
slip31, 2014-05-01
@slip31

Alexander, thanks. Is it

<?=Url::toRoute(['/catalog/view', 'alias' => $model->alias]) ?>
create url from root?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question