如何使用高级模板在Yii2中从前端页面链接到后端....我想链接从frondend到后端的登录按钮...当我点击前端的登录按钮时它可以重定向到后端的登录页面我已经创造了......
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
`
答案 0 :(得分:2)
您可以尝试相对路径
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' =>'Login','url' =>'../../../backend/site/login'];
} else {
将它添加到common / config / main.php中 根据部分
'components' => [
.....
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => false,
'showScriptName' => true,
],
.......
答案 1 :(得分:0)
在frontend / config / main.php中的urlManager之后添加到部分组件
'urlManagerBackend' => [
'class' => 'yii\web\UrlManager',
'baseUrl' => 'http://backend.site.local',
'hostInfo' => 'http://backend.site.local',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
],
在前端/视图/布局中
添加类似的内容
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Admin panel', 'url' => Yii::$app->urlManagerBackend->createUrl([''])],
];