Home >php教程 >php手册 >thinkPHP实现无限级别分类

thinkPHP实现无限级别分类

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 11:40:431013browse

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即可

效果如下:
thinkPHP实现无限级别分类

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:修改ThinkPHP3.2的F方法Next article:tp jquery-upload