ThinkPHP实现无限级别分类

字号+ 编辑: 国内TP粉 修订: SyncLWT 来源: ThinkPHP 2023-09-11 我要说两句(0)

ThinkPHP实现无限级别分类,用递归方法

代码如下:

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

阅完此文,您的感想如何?
  • 有用

    0

  • 没用

    0

  • 开心

    0

  • 愤怒

    0

  • 可怜

    0

1.如文章侵犯了您的版权,请发邮件通知本站,该文章将在24小时内删除;
2.本站标注原创的文章,转发时烦请注明来源;
3.Q群: 2702237 13835667

相关课文
  • mac开发接入微信公众号接口返回报错 cURL error 56: SSLRead() return error -9806

  • PHP的换行符是什么

  • pecl安装程序时报错Array and string offset access syntax with curly braces is no longer supported

  • 由于商家传入的H5交易参数有误,该笔交易暂时无法完成,请联系商家解决

我要说说
网上嘉宾点评