Yii2 menu navbar nav小部件的使用示例
1、menu使用
Menu::widget( [ [ 'label' => $menu['name'], 'url' => [$menu['route']], 'items' => [ [ 'label' => $menu['name'], 'url' => [$menu['route']] ], .... ] ], [ 'label' => $menu['name'], 'url' => [$menu['route']], 'items' => [ [ 'label' => $menu['name'], 'url' => [$menu['route']] ] ] ], .. ] );
2、navbar&&nav
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']], ]; echo Nav::widget([ 'items' => [ [ 'label' => 'Home', 'url' => ['site/index'], 'linkOptions' => [], ], [ 'label' => 'Dropdown', 'items' => [ ['label' => 'Level 1 - Dropdown A', 'url' => '#'], '<li class="divider"></li>', '<li class="dropdown-header">Dropdown Header</li>', ['label' => 'Level 1 - Dropdown B', 'url' => '#'], ], ], [ 'label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest ], ], 'options' => ['class' =>'nav-pills'], // set this to nav-tab to get tab-styled navigation ]); NavBar::end();