找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

thinkphp 中实现无限极分类方法

[复制链接]
发表于 2022-7-14 20:46:18 | 显示全部楼层 |阅读模式
无限极分类


//分类列表

  1. public function lst(){

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


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

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

  5. return $this->fetch();

  6. }
复制代码

//模型方法

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

  2. public function categorytree(){

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

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

  5. }


  6. //分类等级方法

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

  8. static $arr=array();


  9. //foreach 循环执行这个方法

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

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

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

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

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

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

  16. }

  17. }

  18. return $arr;

  19. }
复制代码





发表于 2024-12-29 15:25:48 | 显示全部楼层

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

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

PinUp casino
发表于 2025-1-24 02:09:59 | 显示全部楼层

Valacyclovir

<a href="http://canadianonlinepharmacy.net/">online pharmacy canada</a>
发表于 2025-3-4 11:43:51 | 显示全部楼层

How to start winning

Try reading this - https://ivfrankivsk.if.ua/
Maybe it will help you
发表于 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
发表于 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.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|知识在线

GMT+8, 2026-11-2 20:12 , Processed in 0.156160 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表