S
S
slip312019-04-03 20:36:43
Yii
slip31, 2019-04-03 20:36:43

Can you tell us about UrlManager in Yii2?

Hello. I want to get a link like "directions/allergology", which will go to view.
I do this

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '' => 'site/index',
                'directions/<url>' => 'directions/view/',
              '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
              
            ],
        ],

I prescribe a link
<li><a href="<?=Url::to(['/directions/view', 'url' => $items->url]); ?>"><?=$items->name?></a></li>

Prescribed method
public function actionView($url) {
               $model = Directions::find()->where(['status' => Directions::STATUS_ACTIVE])->andWhere(['url'=>$url])->one();
        return $this->render('view', [
                    'model' => $model]);
    }

When I click on the link, I get "Page not found.".
If I add it to UrlManager , then my link looks like , i.e. with the view and url parameter. What am I doing wrong?
'directions/<url>' => 'directions/view/'<url>,
http://site/directions/view?url=ginecology

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-01-23
@aliasst

img {border-radius:50%; height:100px; width:100px; margin-top:-50px;}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question