欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ThinkPHP菜單無極分類實(shí)例講解

 更新時(shí)間:2021年03月05日 16:50:33   作者:祝君圓夢  
這篇文章主要介紹了ThinkPHP菜單無極分類實(shí)例講解,文中將代碼列舉了出來,有感興趣的同學(xué)可以借鑒參考下

效果圖如下

controller控制器代碼: 

  /**
  * 菜單列表
  */
  public function index(){ 
		$menuList= Db::name('menu')->order('sort,id')->select();
		//遞歸排序
		$menuList= $this->sort($menuList);
		$this->assign('menuList',$menuList);	
    return view();	
  }
	protected function sort($data,$pid=0,$level=0){
		//此處數(shù)據(jù)必須是靜態(tài)數(shù)組,不然遞歸的時(shí)候每次都會(huì)聲明一個(gè)新的數(shù)組
		static $arr = array();
    foreach ($data as $key=>$value){
      if($value['pid'] == $pid){
        $value["level"]=$level;
        $arr[]=$value;
				//unset()用于銷毀指定的變量
				unset($this->data[$key]);
        $this->sort($data,$value['id'],$level+1);
      }
    }
    return $arr;
  }

html模板代碼:

<tbody>
{volist name="menuList" id="vo" key="index"}
  <tr>
    <td class="text-left">
    <?php 
      if($vo['pid']!=0) 
        echo str_repeat("&nbsp;",$vo["level"]*3).'├╌ ' 
        /*str_repeat()函數(shù)把字符串重復(fù)指定的次數(shù)。*/ 
    ?>
    {$vo.name}
    </td>						
  </tr>
{/volist}
</tbody>

到此這篇關(guān)于ThinkPHP菜單無極分類實(shí)例講解的文章就介紹到這了,更多相關(guān)ThinkPHP菜單無極分類內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論