知识学习

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 6260|回复: 5

thinkphp 中实现无限极分类方法

[复制链接]

升级   100%

152

主题

0

回帖

752

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
752
发表于 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. }
复制代码





回复

使用道具 举报

升级   24%

0

主题

4

回帖

12

积分

新手上路

Rank: 1

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

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

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

PinUp casino
回复

使用道具 举报

升级   12%

0

主题

1

回帖

6

积分

新手上路

Rank: 1

积分
6
发表于 2025-1-24 02:09:59 | 显示全部楼层

Valacyclovir

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

使用道具 举报

升级   68%

0

主题

2

回帖

34

积分

新手上路

Rank: 1

积分
34
发表于 2025-3-4 11:43:51 | 显示全部楼层

How to start winning

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

使用道具 举报

升级   84%

0

主题

2

回帖

42

积分

新手上路

Rank: 1

积分
42
发表于 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
回复

使用道具 举报

升级   24%

0

主题

2

回帖

12

积分

新手上路

Rank: 1

积分
12
发表于 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|手机版|小黑屋|知识学习 ( 鲁ICP备20015483号 )

GMT+8, 2026-5-13 21:56 , Processed in 0.104196 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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