首页 > 其他 > 详细

yii2顶部导航使用

时间:2014-07-22 00:26:06      阅读:629      评论: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();
        ?>

   bubuko.com,布布扣

效果如下图:

bubuko.com,布布扣

yii2顶部导航使用,布布扣,bubuko.com

yii2顶部导航使用

原文:http://www.cnblogs.com/xlz307/p/3858067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!