PHP code example of lyxxxh / lartree
1. Go to this page and download the library: Download lyxxxh/lartree library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lyxxxh / lartree example snippets
//引入命名空间
use Xxh\LarTree\Services\LarTreeServices;
class LarController extends Controller {
use LarTree; //使用LarTree
public function index()
{
//设置需要的字段 为了更快速 不设置也可以
$this->setField(['id','pid','name']);
//默认是id pid
// $this->setFatherSonName('子id','父id');
//设置表 把查询到的所有结果先存到$datas变量
$this->initTableConainer('users');
//最开始的父id
$data = $this->getTableTree(0);
dd($data);//获取树结构了
}
}