fastadmin的无限极分类

280 阅读1分钟

首先你需要引用

use fast\Tree;

然后,你需要得到需要的值

//查询条件:
  		$search = $this->request->request("search");
 //查询类型
        $type = $this->request->request("type");
 //查询开始位置
        $offset = $this->request->request("offset");
 //每页查询限制
        $limit = $this->request->request("limit");

然后我们就可以使用咯,开始

//来先制造恐慌,开玩笑的,别当真
        $list = [];
// 调用类的初始化方法
   $tree = Tree::instance();
   //给他赋予一个参数
   //下面是本大人的解说时间
   //$this->model->order('id desc')->select()  模型查询的对象
   //collection(查询出来的对象)->toArray()  把对象转成数组
   //$tree->init(数组,上级关系字段)
   //当当当,就变成这样咯
   //  $tree->init(collection($this->model->order('id desc')->select())->toArray(), 'pid');
    $tree->init(collection($this->model->order('id desc')->select())->toArray(), 'pid');
	//getTreeArray获取数组,getTreeList 进行排序
	//$tree->getTreeList(数组, 需要判断的字段)
    $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
    //好的打完收工咯,哈哈哈哈哈哈哈	
	//剩下的就交给你们了 晚安,亲
    $categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
    foreach ($this->categorylist as $k => $v) {
        $categorydata[$v['id']] = $v;
    } 

  
        $total = count( $this->categorylist);
        $result = array("total" => $total, "rows" =>  array_slice($this->categorylist,$offset,$limit));

在这里插入图片描述