Skip to content

Commit 9038f86

Browse files
committed
完善文档信息
1 parent 8b5bea0 commit 9038f86

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# infinite-tree
2+
3+
[中文文档](README.md) | [English manual](README_EN.md)
4+
25
php的无限树工具包
36

47
>之前我已经写过一个无限级分类的PHP包名称叫tp5-nestedsets在packagist上的安装量还是挺大的。但是tp5-nestedsets是基于tp5的很显然其灵活性不够高。而infinite-tree是一个不受框架限制的无限级分类的包。

README_EN.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# infinite-tree
2+
3+
[中文文档](README.md) | [English manual](README_EN.md)
4+
5+
Php infinite tree toolkit
6+
7+
>I have written an infinite-level classification of the PHP package name tp5-nestedsets installed on the packagist is still quite large. But tp5-nestedsets is based on tp5 framework and it is obviously not flexible enough. Infinite-tree is an infinite-level classification package that is not restricted by the framework.
8+
9+
## About the application scenario
10+
Someone who posted the tp5-nestedsets gave me a message saying that in general, there are only three levels of classification, and the three-level classification is bound by id and parent_id. Why is this infinite package necessary?
11+
12+
First of all, the classification of this tree-related data in the package is described by the tree relationship. The search and operation are all in accordance with the operation mode of the tree. Obviously, it is more convenient and efficient than traversing according to id and parent_id. Just take it simple. You need to query up to 3 times for all descendant classifications of a top-level classification of a three-level classification, and recursion is not efficient. But you can use this toolkit once to check it out. In fact, the level of classification in reality is really more than just three levels. The three levels we see are generally created by virtual classifications. The user feels that it is a three-level classification. In fact, it is much more complicated than this. It may not be this. The problem that the package can solve may be to use feature values, search, etc.
13+
## Use
14+
### Condition
15+
Before using it, make sure you have the mysqli extension. Generally, PHP has this extension. It was originally intended to be compatible with the mysql extension, but the subsequent PHP version also abandoned the mysql extension and all are not compatible.
16+
### Installation
17+
```php
18+
composer require gmars/infinite-tree
19+
```
20+
If you haven't used composer yet, please see the related tutorial for composer installation.
21+
22+
### Instantiating InfiniteTree
23+
>Because you want to leave the specific framework, the database configuration needs to be configured by yourself.
24+
25+
```php
26+
/ / This part is the database configuration array
27+
$dbConfig = [
28+
    'hostname' => '127.0.0.1',
29+
    'username' => 'root',
30+
    'password' => 'root',
31+
    'database' => 'test',
32+
    'hostport' => 3306
33+
];
34+
35+
/ / This part is the key configuration in the data table. If it is consistent with the default, you can configure it.
36+
$keyConfig = [
37+
    'left_key' => 'left_key',
38+
    'right_key' => 'right_key',
39+
    'level_key' => 'level',
40+
    'primary_key' => 'id',
41+
    'parent_key' => 'parent_id'
42+
];
43+
$infiniteTree = new InfiniteTree('tree', $dbConfig, $keyConfig);
44+
```
45+
The first parameter when instantiating is your table name, the second is the database configuration, and the third is the key mapping.
46+
47+
### Create a data table
48+
If you haven't created a data table yet, this method will create a data table. Specific other required fields you can add manually after creating.
49+
```php
50+
$infiniteTree->checkTable()
51+
```
52+
53+
### Method Description
54+
55+
Get the entire tree structure
56+
```php
57+
$infiniteTree->getTree()
58+
```
59+
60+
Get all descendant nodes of $id (do not include themselves)
61+
```php
62+
$infiniteTree->getBranch($id)
63+
```
64+
65+
Get all child nodes of $id (note that only child nodes)
66+
```php
67+
$infiniteTree->getChildren($id)
68+
```
69+
70+
Get node $id and all descendant nodes
71+
```php
72+
$infiniteTree->getPath($id)
73+
```
74+
75+
The child node inserted under the node $id contains the extended data name, and is inserted at the bottom of all child nodes of $id. If the third parameter is top, it is inserted before all child nodes.
76+
```php
77+
$infiniteTree->insert($id, ['name' => 'test node'], 'bottom')
78+
```
79+
80+
Move the node with id 8 to the node with id 1
81+
```php
82+
$infiniteTree->moveUnder(8, 1)
83+
```
84+
85+
Move the node with id 8 to the front of the node with id 2 (before) if you want to move to the back is after
86+
```php
87+
$infiniteTree->moveNear(8, 2, "before")
88+
```
89+
90+
### Precautions
91+
92+
1. In the previous version, getItem has a static cache in the object. It feels unnecessary to add it in this version. Please control the cache yourself.
93+
2. For the left and right values ​​to define the tree knowledge, if you are not very clear, please consult the corresponding information.
94+
3. If you have any questions, please submit an issue.
95+
4. If it feels convenient to use, please click on the star above.

0 commit comments

Comments
 (0)