AI智能
改变未来

thinkphp用后盾网的数组增强插件实现栏目的树状结构

1、下载后盾网的arr

Composer require houdunwang/arr

2、配置文件以供使用
将use houdunwang\\arr\\arr;改成Houdunwang\\Arr\\Arr;
且Arr.php文件和category文件都需要更改。

否则报错non-static method xxx()should not be called statically
class Houdunwang\\Arr\\Arr;不存在

3、使用
在需要使用的model中声明houdunwang\\Arr\\Arr;
在需要用的数组中 用Arr::tree();

下面是使用实例

public function getAll(){Return Arr::tree(db(‘cate’)->order(‘cate_sort desc’)->select(),’cate_name’,$fieldPri=’cate_id’,$fieldPid=’cate_pid’)}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » thinkphp用后盾网的数组增强插件实现栏目的树状结构