A
A
Alexander Ivanov2017-04-29 10:38:02
Yii
Alexander Ivanov, 2017-04-29 10:38:02

How to set URL for posts in yii2?

The following URLs are obtained from the code below => site.ru/blog/1/
How to replace 1 with TEXT?

//мой маршруизатор
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
//            'enableStrictParsing' => true,
            'suffix' => '/',
            'rules' => [
                ''=>'site/index',
                '<module:\w+>/<id:\d+>' => '/<module>/default/view',
                '<action:\w+>'=>'site/<action>',
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            ]
          // ...
        ],

// вывожу страницы
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

I understand it matters advanced or base. I have base installed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-04-29
@cimonlebedev

Implement your own class of rules that will replace the id-shku with the alias specified in the article

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question