代碼如下:
public $cateListAll = array(); public function editCate() { $this->cateChildList(0,$nb); // 從父級=0開始遞歸 $this->cateList=$this->cateListAll; $this->display(); } // 無限極分類 protected function cateChildList($pid,$nb) { $cate=M('cate'); $parent=$cate->where('parent_id="'.$pid.'"')->order('sort asc,id desc')->select(); if($parent) { $nb = $nb." "; foreach($parent as $item) { $item['name']=$nb.'├ '.$item['name']; $this->cateListAll[]=$item; $this->cateChildList($item['id'],$nb); } } }
其中前台html直接循環cateList即可