Reputation: 503
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>',
],
.
.
.
Upvotes: 0
Views: 182
Reputation: 1020
Create another url manager in frontend and set the baseurl to direct it to backend and add your backend rules if any. And use the created component for creating backend urls
'urlManagerBackend' => [
'baseUrl' => str_replace('/frontend/web', '/backend/web', (new Request)->getBaseUrl()),
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
And vice-versa for backend to frontend
*and yes also include this in config
use \yii\web\Request;
Upvotes: 1