如何對yii中的多級菜單進行查詢?使用Yii創建多級菜單
比如我有一個這樣的表:
menu_name
將遵循parrent_id
它,所以它會形成一個hierarchical
菜單
如何使用Yii
在我的佈局上使輸出成爲html以上
我的代碼:
<?php
Yii::import('zii.widgets.CMenu', true);
class ActiveMenu extends CMenu
{
public function init(){
$criteria = new CDbCriteria;
$criteria->condition='published=:idpub AND menu_controller=:menu';
$criteria->params=array(':idpub'=>1, ':menu'=>'#');
$items = Menu::model()->findAll($criteria);
echo "<ul id='yw1' class='nav'>";
foreach ($items as $item)
{
echo "<li class='dropdown'>
<a href=".$item->menu_controller." data-toggle='dropdown' class='dropdown-toggle'>
<i class='icon-white icon-list'></i>".$item->menu_name."<b class='caret'></b></a>
</li>";
}
echo "</ul>";
parent::init();
}
}
但是在上面的代碼我只得到parents data
。我怎麼想循環得到childs data
包括在這樣的HTML代碼中每一個做父母的菜單:
<ul id="yw1" class="nav">
<li><a href="/app/home.html"><span class="icon-white icon-tasks"></span> Home</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">
<i class="icon-white icon-list"></i>Master<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="expedition"><span class="icon-bar icon-list"></span> Expedition</a></li>
</ul>
<ul class="dropdown-menu">
<li><a href="partner"><span class="icon-bar icon-list"></span> Partner</a></li>
</ul>
<ul class="dropdown-menu">
<li><a href="user"><span class="icon-bar icon-list"></span> User</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">
<i class="icon-white icon-list"></i>Transaction<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="processin"><span class="icon-bar icon-list"></span> Process In</a></li>
</ul>
<ul class="dropdown-menu">
<li><a href="processout"><span class="icon-bar icon-list"></span> Process Out</a></li>
</ul>
etc ....
etc ....
etc ....
</li>
</ul>
感謝
你的孩子你爲什麼要改變CActiveMenu的實現?你也可以在你的視圖中做 –