admin 发表于 2022-7-14 20:46:18

thinkphp 中实现无限极分类方法

无限极分类


//分类列表

public function lst(){

$category=new CategoryModel; //引用模型等于一个变量


$data=$category->categorytree(); //查询所有分类 -- 模型的方法

$this->assign('c_list',$data); //模板变量复制

return $this->fetch();

}
//模型方法

//无限极分类的树形结构方法

public function categorytree(){

$categoryres=$this->select(); //自己查询等于$categoryres变量

return $this->sort($categoryres); //自己指向 sort方法带上 $categoryres变量

}


//分类等级方法

public function sort($data,$pid=0,$level=0){

static $arr=array();


//foreach 循环执行这个方法

foreach ($data as $k => $v){

if($v['pid']==$pid){ //第一次循环等级一定为0

$v['level']=$level; //新的临时的一维数组记录等级

$arr[]=$v; //等级赋值给一维数组记录

$this->sort($data,$v['id'],$level+1); //每次有下以级别 执行此方法

//每循环一次foreach方法 level(等级)就加1

}

}

return $arr;

}




DavidAbsek 发表于 2024-12-29 15:25:48

我们给出了一个存款的促销代码!

新年只为你
我们在注册或免费旋转时支付定金

PinUp casino

hewittbobTed 发表于 2025-1-24 02:09:59

Valacyclovir

<a href="http://canadianonlinepharmacy.net/">online pharmacy canada</a>

Edgarjucky 发表于 2025-3-4 11:43:51

How to start winning

Try reading this - https://ivfrankivsk.if.ua/
Maybe it will help you

RobertWheft 发表于 2025-3-4 13:46:50

How to start winning

hewittbobTed ??? 2025-1-24 02:09
online pharmacy canada

Try reading this - https://ivfrankivsk.if.ua/
Maybe it will help you

Arisha10Ei 发表于 2025-3-25 11:25:11

Great reading too 10 .

RobertWheft ??? 2025-3-4 13:46
Try reading this - https://ivfrankivsk.if.ua/
Maybe it will help you

Hello !
Hi. A 10 very cool site 1 that I found on the Internet.
Check out this site. There's a great article there. <a href=https://mashssl.org/roulette-hacks/everything-you-need-to-know-about-bob-casino-login/>https://tandoori-grill.com/table-games-rules/how-to-get-value-on-a-game/</a>|

There is sure to be a lot of useful and interesting information for you here.
You'll find everything you need and more. Feel free to follow the link below.
页: [1]
查看完整版本: thinkphp 中实现无限极分类方法