码迷,mamicode.com
首页 > 其他好文 > 详细

yii2顶部导航使用

时间:2016-04-14 22:09:44      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

yii2中使用顶部导航的具体方法:

1.视图中调用两个类:

use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;

2. <?php
            NavBar::begin([
                ‘brandLabel‘ => ‘My Company‘,
                ‘brandUrl‘ => Yii::$app->homeUrl,
                ‘options‘ => [
                    ‘class‘ => ‘navbar-inverse navbar-fixed-top‘,
                ],
            ]);
            $menuItems = [
                [‘label‘ => ‘Home‘, ‘url‘ => [‘/site/index‘]],
                [‘label‘=>‘注册‘,‘url‘=>[‘/manager/register‘]],
                [‘label‘=>‘关于我们‘,‘url‘=>[‘/site/about‘]],
            ];
            if (Yii::$app->user->isGuest) {
                $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();
        ?>

   技术分享

效果如下图:

技术分享

yii2顶部导航使用

标签:

原文地址:http://www.cnblogs.com/jiuweidezhanfang/p/5392698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!