thinkPHP实现无限级别分类,用递归方法
代码如下:public $cateListAll = array();<br>
public function editCate()<br>
{<br>
$this->cateChildList(0,$nb);//从父级=0开始递归<br>
$this->cateList=$this->cateListAll;<br>
$this->display();<br>
}<br>
<br>
//无限极分类<br>
protected function cateChildList($pid,$nb)<br>
{<br>
$cate=M('cate');<br>
$parent=$cate->where('parent_id="'.$pid.'"')->order('sort asc,id desc')->select();<br>
if($parent)<br>
{<br>
$nb = $nb." ";<br>
foreach($parent as $item)<br>
{<br>
$item['name']=$nb.'├ '.$item['name'];<br>
$this->cateListAll[]=$item;<br>
$this->cateChildList($item['id'],$nb);<br>
}<br>
}<br>
}
其中前台html直接循环cateList即可
效果如下:
AD:真正免费,域名+虚机+企业邮箱=0元