本文介绍了Yii2 链接前端到后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用高级模板在 Yii2 中从前端页面链接到后端......我想将登录按钮从前端链接到后端......当我点击前端的登录按钮时,它可以重定向到后端的登录页面我已经创建...
<?php导航栏::开始(['品牌标签' =>'我的公司','brandUrl' =>Yii::$app->homeUrl,'选项' =>['类' =>'导航栏反向导航栏固定顶部',],]);$menuItems = [['标签' =>'首页', '网址' =>['/站点/索引']],['标签' =>'关于', 'url' =>['/网站/关于']],['标签' =>'联系方式', 'url' =>['/网站/联系人']],];if (Yii::$app->user->isGuest) {$menuItems[] = ['label' =>'注册', 'url' =>['/网站/注册']];$menuItems[] = ['label' =>'登录', 'url' =>['/网站/登录']];} 别的 {$menuItems[] = ['标签' =>'注销(' .Yii::$app->用户->身份->用户名.')','网址' =>['/站点/注销'],'linkOptions' =>['数据方法' =>'邮政']];}回声导航::小部件(['选项' =>['类' =>'导航栏-导航栏-右'],'物品' =>$菜单项,]);导航栏::结束();?><div class="容器"><?= 面包屑::小部件(['链接' =>isset($this->params['breadcrumbs']) ?$this->params['breadcrumbs'] : [],]) ?><?= Alert::widget() ?><?= $content ?>
`
解决方案
在frontend/config/main.php中添加到urlManager之后的section组件
'urlManagerBackend' =>['类' =>'yii\web\UrlManager','baseUrl' =>'http://backend.site.local','hostInfo' =>'http://backend.site.local','enablePrettyUrl' =>真的,'enableStrictParsing' =>真的,'showScriptName' =>错误的,],
在前端/视图/布局中
添加类似的东西
$menuItems = [['标签' =>'首页', '网址' =>['/站点/索引']],['标签' =>'管理面板', 'url' =>Yii::$app->urlManagerBackend->createUrl([''])],];
How to link from frontend page to backend in Yii2 using advanced template.... I want to link the login button from frondend to backend...when I click on login button in frontend it can redirect to login page in backend that I already created...
<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>
`
解决方案
add to section components after urlManager in frontend/config/main.php
'urlManagerBackend' => [
'class' => 'yii\web\UrlManager',
'baseUrl' => 'http://backend.site.local',
'hostInfo' => 'http://backend.site.local',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
],
in frontend/views/layout
add something like this
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Admin panel', 'url' => Yii::$app->urlManagerBackend->createUrl([''])],
];
这篇关于Yii2 链接前端到后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!