yii2 常用组件 -- 导航组件(Nav)

简介

在yii2的开发过程中,导航组件(Nav)的适用场景也是非常多的,比如在yii2布局文件中默认导航就是使用Nav组件。那么本文就来介绍一下yii2的导航组件(Nav)的用法。

实例

<?php
use yii\bootstrap\Nav;

echo Nav::widget([
 'items' => [
     [
         'label' => 'Home',
         'url' => ['site/index'],
         'linkOptions' => ['class'=>'style'],  //设置链接的样式
     ],
     [
         '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'], // 设置导航的样式
]);

以上就是导航组件(Nav)的简单应用,然后通过调整与样式整理就可以开发出更加复杂的导航,非常的简单方便

演示

本站的导航就是使用导航组件(Nav)开发而成

blob.png


发布了2 篇原创文章 · 获赞 0 · 访问量 8051
展开阅读全文

Yii:使用图像在Navbar中进行本地化

11-13

<div class="post-text" itemprop="text"> <p>It would be nice to have a Dropdown menu with several flags.Is there a way to show a image like a Flag in the navigation when I use twitter-bootstrap? If I select one flag, the language and the flag should change.</p> <p>I can show the bootstrap supported Icons but they contain no flags. </p> <p>I hope some can help me. below is my navigation.</p> <pre><code> $this->widget('bootstrap.widgets.TbNavbar', array( 'type' => 'null', // null or 'inverse' 'brand' => '<img src="http://localhost/images/logo.gif">', 'brandUrl' => 'localhost', 'collapse' => true, // requires bootstrap-responsive.css 'items' => array( array( 'class' => 'bootstrap.widgets.TbMenu', 'type' => 'pills', // '', 'tabs', 'pills' (or 'list') 'items' => array( array('label' => 'Home', 'url' => array('/site/index')), array('label' => 'user create', 'url' => array('/account/user/create')), array('label' => 'Contact', 'url' => array('/site/contact')), array('label' => 'User', 'url' => array('/account/user/index')), ), ), array( 'class' => 'bootstrap.widgets.TbMenu', 'type' => 'pills', // '', 'tabs', 'pills' (or 'list') 'htmlOptions' => array('class' => 'pull-right'), 'items' => array( /**Added to show, that here should appear the flag*/ array('label' => '','htmlOptions'=> array('src'=>'http://localhost/images/german.png'), 'url' => ''), array('label' => 'Sign in', 'url' => array('/account/signup/login'), 'visible' => Yii::app()->user->isGuest), array('label' => 'Sign up', 'url' => array('/account/signup/registration'), 'visible' => Yii::app()->user->isGuest), array('label' => Yii::app()->user->name , 'url' => '#', 'items' => array( array('label' => 'Action', 'url' => '#'), array('label' => 'Another action', 'url' => '#'), array('label' => 'Something else here', 'url' => '#'), '---', array('label' => 'Logout', 'url' => array('/account/signup/logout')), ),'visible' => !Yii::app()->user->isGuest), ), ), ), )); </code></pre> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览