最近在使用yii框架的时候,想做一个头部导航的分类,因为在开发的时候,考虑到了要兼容移动端,所以,内嵌了bootstrap,其实,yii在处理分类,多级分类的时候还是挺简单的,下面就让我们看看具体的一个例子吧:
<nav class="navbar navbar-default" role="navigation"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse"> <span class="sr-only">切换导航</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="navbar-brand visible-xs"> <a href="/" rel="nofollow">Home</a> | <a href="" rel="nofollow">Creat My Trip</a> </div> </div> <div class="collapse navbar-collapse" id="example-navbar-collapse"> <?php $this->widget(‘zii.widgets.CMenu‘, array( ‘activeCssClass‘=>‘activeli‘, ‘firstItemCssClass‘=>‘fistli‘, ‘lastItemCssClass‘=>‘lastli‘, ‘encodeLabel‘ =>false, ‘htmlOptions‘=>array(‘class‘=>‘nav navbar-nav‘), ‘submenuHtmlOptions‘ =>array(‘class‘=>‘dropdown-menu‘), ‘items‘=>array( array(‘label‘=>‘china tours‘, ‘url‘=>array(‘site/index‘),‘itmeOptions‘=>array(‘id‘=>‘China tours‘)),//為li添加id array(‘label‘=>‘destinations‘, ‘url‘=>array(‘site/contact‘),‘itemOptions‘=>array(‘class‘=>‘dropdown‘),//‘linkOptions‘=>array(‘class‘=>‘dropdown-toggle‘,‘data-toggle‘=>‘dropdown‘), ‘items‘=>array( array(‘label‘=>‘New Arrivals‘, ‘url‘=>array(‘product/new‘, ‘tag‘=>‘new‘)), array(‘label‘=>‘Most Popular‘, ‘url‘=>array(‘product/index‘, ‘tag‘=>‘popular‘)), ) ), array(‘label‘=>‘heritage tours‘, ‘url‘=>array(‘site/login‘),‘itemOptions‘=>array(‘class‘=>‘dropdown‘), ‘items‘=>array( array(‘label‘=>‘New Arrivals 1‘, ‘url‘=>array(‘product/new‘, ‘tag‘=>‘new‘)), array(‘label‘=>‘Most Popular 1‘, ‘url‘=>array(‘product/index‘, ‘tag‘=>‘popular‘)), ), ‘visible‘=>Yii::app()->user->isGuest ), array(‘label‘=>‘shore excursions‘, ‘url‘=>array(‘site/index‘),‘itmeOptions‘=>array(‘id‘=>‘shore excursions‘)), ), )); ?> </div> </nav>
用过bootstrap的人都知道,这样写的目的。先记录一下,以后也许会用到吧
时间: 2024-10-06 11:12:47