A
A
Alexey Voropaev2016-06-13 14:31:59
Yii
Alexey Voropaev, 2016-06-13 14:31:59

How to implement urlManager from backEnd to frontEnd and vice versa?

You need to implement urlManager so that Yii::$app->urlManagerFrontEnd and Yii::$app->urlManagerBackEnd are available in backEnd and frontEnd. I found many solutions in Google, everyone does it in their own way, but I didn’t like the options. How I do:
Step 1: added 2 parameters to common/config/params.php

'domainFrontEnd' => 'yii2',
'domainBackEnd' => 'admin.yii2'

Step 2: in common/config/main.php added
'components' => [
        'urlManagerFrontEnd' => [
            'class' => 'yii\web\UrlManager',
            'baseUrl' => '',
            'hostInfo' => $domainFrontEnd,
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
        ],
        'urlManagerBackEnd' => [
            'class' => 'yii\web\UrlManager',
            'baseUrl' => '',
            'hostInfo' => $domainBackEnd,
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
        ],
    ],

Step 3: in backEnd I call but the link is admin/yii2/ , although it should be yii2/ What am I doing wrong? In Google they write that you need to implement routes and in the examples you have your own routes. I need standard routes like module/controller/action/params
Yii::$app->urlManagerFrontEnd->createUrl('')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Greg Popov, 2016-06-13
@boomrap

And why such dances with a tambourine? Separate admin and front by URL for transitions like example.com/admin?
Take a look at this .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question