Answer the question
In order to leave comments, you need to log in
How to write a link?
['label' => 'About', 'url' => ['/site/about']]
how to write here to go from frontend to backend ????
Answer the question
In order to leave comments, you need to log in
frontend and backend are separate app. And the url manager of one app is unaware of the existence of the second. Therefore, you need to make another urlManager in the frontend config, which will know about the backend. And use it when generating links.
For example:
//это стандарный
'urlManager' => [
'class' => 'yii\web\urlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
],
//это второй
'urlManagerBack' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://mybackenddomain.com',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => require(__DIR__ . '/../../backend/config/routes.php'), //тут путь к файлу с rules для backend
],
Yii::$app->urlManagerBack->createAbsoluteUrl('/'); //ссылка на главную
Yii::$app->urlManagerBack->createUrl(['site/about']); //Ваш пример
front end
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'urlManagerBack' => [
'class' => 'yii\web\UrlManager',
'baseUrl' => 'localhost/fashion-house',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => require(__DIR__ . '/../../backend/config/main.php'), //тут путь к файлу с rules для backend
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
],
'params' => $params,
];
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
],
'params' => $params,
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question