title: Create multi level menu using Yii
body: <p>How do I do a query to the case of multi-level menus in yii?</p>
  
  <p>For example I have a table like this :</p>
  
  <p><img src="https://i.stack.imgur.com/TToSG.png" alt="enter image description here"></p>
  
  <p><code>menu_name</code> will follow <code>parrent_id</code> it has, so it will form a <code>hierarchical</code> menu</p>
  
  <p><img src="https://i.stack.imgur.com/K83Gr.png" alt="enter image description here"></p>
  
  <p>How do I use <code>Yii</code> on my layout so that the output as html above</p>
  
  <p>My code :</p>
  
  <pre><code>&lt;?php
  Yii::import('zii.widgets.CMenu', true);
  
  class ActiveMenu extends CMenu
  {
      public function init(){
  
      $criteria = new CDbCriteria;
      $criteria-&gt;condition='published=:idpub AND menu_controller=:menu';
      $criteria-&gt;params=array(':idpub'=&gt;1, ':menu'=&gt;'#');
  
      $items = Menu::model()-&gt;findAll($criteria);
  
      echo "&lt;ul id='yw1' class='nav'&gt;";
  
          foreach ($items as $item)
          {
              echo "&lt;li class='dropdown'&gt;
                      &lt;a href=".$item-&gt;menu_controller." data-toggle='dropdown' class='dropdown-toggle'&gt;
                      &lt;i class='icon-white icon-list'&gt;&lt;/i&gt;".$item-&gt;menu_name."&lt;b class='caret'&gt;&lt;/b&gt;&lt;/a&gt;
                  &lt;/li&gt;";
          }
  
          echo "&lt;/ul&gt;";
  
          parent::init();
      }
  }
  </code></pre>
  
  <p>But in the above code I only get <code>parents data</code>. How do I want to loop to get the <code>childs data</code> include in every parents menu like this html code :</p>
  
  <pre><code>&lt;ul id="yw1" class="nav"&gt;
      &lt;li&gt;&lt;a href="/app/home.html"&gt;&lt;span class="icon-white icon-tasks"&gt;&lt;/span&gt; Home&lt;/a&gt;&lt;/li&gt;
  
      &lt;li class="dropdown"&gt;
          &lt;a href="#" data-toggle="dropdown" class="dropdown-toggle"&gt;
          &lt;i class="icon-white icon-list"&gt;&lt;/i&gt;Master&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="expedition"&gt;&lt;span class="icon-bar icon-list"&gt;&lt;/span&gt; Expedition&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="partner"&gt;&lt;span class="icon-bar icon-list"&gt;&lt;/span&gt; Partner&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="user"&gt;&lt;span class="icon-bar icon-list"&gt;&lt;/span&gt; User&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  
      &lt;li class="dropdown"&gt;
          &lt;a href="#" data-toggle="dropdown" class="dropdown-toggle"&gt;
          &lt;i class="icon-white icon-list"&gt;&lt;/i&gt;Transaction&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="processin"&gt;&lt;span class="icon-bar icon-list"&gt;&lt;/span&gt; Process In&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="processout"&gt;&lt;span class="icon-bar icon-list"&gt;&lt;/span&gt; Process Out&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          etc ....
          etc ....
          etc ....
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Thanks</p>