Yii2 Links between Frontend and Backend

Hi guys,

how can I switch from frontend to backend using links in yii2 application? Actually, I only can set links between frontend or backend, not from frontend to backend.

I suppose, I have to change my config-file(main-local.php/urlManager) So, here it is:




.

.

.'urlManager' => [

                'class' => 'yii\web\UrlManager',

                'enablePrettyUrl' => true,

                'showScriptName' => true,

                'enableStrictParsing' => true,

                'rules' => [

                    '/' => 'site/login',

                    'home' => 'site/index',

                    'reset' => 'site/request-password-reset',

                    'about' => 'site/about',

                    'contact' => 'site/contact',

                    'logout' => 'site/logout',

                    'signup' => 'site/signup',

                    'gii' => '/gii',

                    'debugger' => '/debug',

                    '<controller:\w+>/<id:\d+>' => '<controller>/view',

                    '<controller:\w+>/<id:\d+>' => '<controller>/save-as-new',

                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

                    '<action:(contact|captcha)>' => 'site/<action>',

                ],

                .

                .

                .



Got solution by my own:

Step 1: remove all rules and urlManager-settings from main-local.php

Step2: supplement main.php in frontend with following code:




...

     'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName' => true,

            'enableStrictParsing' => true,

            'class' => 'yii\web\UrlManager',

            'rules' => [

                '/' => 'site/login',

                'home' => 'site/index',

                'reset' => 'site/request-password-reset',

                'about' => 'site/about',

                'contact' => 'site/contact',

                'logout' => 'site/logout',

                'signup' => 'site/signup',

                '<controller:\w+>/<id:\d+>' => '<controller>/view',

                '<controller:\w+>/<id:\d+>' => '<controller>/save-as-new',

                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

                '<action:(contact|captcha)>' => 'site/<action>',

            ],

        ],

        'urlManagerBackend' => [

            'class' => 'yii\web\UrlManager',

            'baseUrl' => '/yii2_perswitch/backend/web/yiic.php',

        ],

...



Step2: supplement main.php in backend with following code:




...

    'urlManager' => [

            'enablePrettyUrl' => false,

            'showScriptName' => false,

            'enableStrictParsing' => false,

            'class' => 'yii\web\UrlManager',

        ],

        'urlManagerFrontend' => [

            'class' => 'yii\web\UrlManager',

            'baseUrl' => '/yii2_perswitch/frontend/web/yiic.php',

        ],

...



Step4: Use following link from frontend->backend




      <?=

        Menu::widget(

                [['label' => 'Backend', 'icon' => 'vimeo', 'url' => \Yii::$app->urlManagerBackend->baseUrl . '/yiic.php?r=site%2Findex'],              

])

        

            ]

Step4: Use following link from backend->frontend




         ['label' => 'Frontend', 'icon' => 'vimeo', 'url' => \Yii::$app->urlManagerFrontend->baseUrl . '/home'],