PHP code example of gmars / infinite-tree

1. Go to this page and download the library: Download gmars/infinite-tree 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/ */

    

gmars / infinite-tree example snippets


composer 

//这一部分是数据库配置数组
$dbConfig = [
    'hostname' => '127.0.0.1',
    'username' => 'root',
    'password' => 'root',
    'database' => 'test',
    'hostport' => 3306
];

//这一部分是数据表中的键配置如果和默认一致可以不用配置
$keyConfig = [
    'left_key' => 'left_key',
    'right_key' => 'right_key',
    'level_key' => 'level',
    'primary_key' => 'id',
    'parent_key' => 'parent_id'
];
$infiniteTree = new InfiniteTree('tree', $dbConfig, $keyConfig);

$infiniteTree->checkTable()

$infiniteTree->getTree()

$infiniteTree->getBranch($id)

$infiniteTree->getChildren($id)

$infiniteTree->getPath($id)

$infiniteTree->insert($id, ['name' => '测试节点'], 'bottom')

$infiniteTree->moveUnder(8, 1)

$infiniteTree->moveNear(8, 2, "before")