If i need add links to frontend stuff from backend part in menu(or from backend to admin), how i can do this without hardcode? This:
\Yii::$app->request->BaseUrl
returns path from parents dir
/sitename/backend/web
/sitename/frontend/web
In your backend application config you should add additional 'UrlManager' component with different name and configuration equals to the one used at front end application:
return [
'components' => [
'urlManager' => [
// here is your backend URL rules
],
'urlManagerFrontEnd' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/a/frontend/web',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
Then you should invoke following to compose front-end URL:
Yii::$app->urlManagerFrontEnd->createUrl();
My mistake - I was incorrectly sent link value.
Wrong:
$menuItems[] = ['label'=>'frontend', 'url'=>[\Yii::$app->urlManagerFrontEnd->baseUrl]];
Thats Works:
$menuItems[] = ['label'=>'frontend', 'url'=>\Yii::$app->urlManagerFrontEnd->baseUrl];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With