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.交流群: 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交易參數有誤,該筆交易暫時無法完成,請聯繫商家解決

我要說說
網上賓友點評