yii2顶部导航使用

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顶部导航使用

效果如下图:

yii2顶部导航使用

上一篇:在终端中创建一个简单的mysql表格


下一篇:C/C++代码静态分析插件 SourceInsight_Scan