Answer the question
In order to leave comments, you need to log in
How to link to backend from frontend in Yii2?
How to add a link to the backend in the frontend menu?
UPD 1:
\yii2rbac\frontend\config\main.php
'components' => [
'urlManager' => [
// 'class' => 'backend\components\UrlManager',
'enablePrettyUrl' => true,
// 'rules' => require(__DIR__ . '/routes.php'),
],
'urlManagerFrontend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://localhost/yii2rbac',
'enablePrettyUrl' => true,
'showScriptName' => false,
//'rules' => require(__DIR__ . '../frontend/routes.php'),
],
'components' => [
'urlManager' => [
// 'class' => 'backend\components\UrlManager',
'enablePrettyUrl' => true,
// 'rules' => require(__DIR__ . '/routes.php'),
],
'components' => [
'urlManager' => [
'class' => 'yii\web\urlManager',
'enablePrettyUrl' => true,
],
$menuItems = [
['label' => 'back', 'url' => Yii::$app->urlManagerFrontend->createUrl('backend/web/index.php'),],
Set document roots of your Web server:
For Apache:
<VirtualHost *:80>
ServerName www.yii2-start.domain # You need to change it to your own domain
ServerAlias yii2-start.domain # You need to change it to your own domain
DocumentRoot /my/path/to/yii2-start # You need to change it to your own path
<Directory /my/path/to/yii2-start> # You need to change it to your own path
AllowOverride All
</Directory>
</VirtualHost>
Use the URL http://yii2-start.domain to access application frontend.
Use the URL http://yii2-start.domain/backend/ to access application backend.
Answer the question
In order to leave comments, you need to log in
In order to be able to form links to backend controllers in the frontend, you need to add a new UrlManager to the frontend.
In \yii2rbac\frontend\config\main.php add the following component
'urlManagerBackend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://yoursitedomain.ru',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => require(__DIR__ . '../backend/routes.php'),
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question