Download the PHP package paulzi/yii2-nested-sets without Composer
On this page you can find all versions of the php package paulzi/yii2-nested-sets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paulzi/yii2-nested-sets
More information about paulzi/yii2-nested-sets
Files in paulzi/yii2-nested-sets
Package yii2-nested-sets
Short Description Nested Sets Behavior for Yii2
License MIT
Informations about the package yii2-nested-sets
Yii2 Nested Sets Behavior
Implementation of nested sets algorithm for storing the trees in DB tables.
Install
Install via Composer:
or add
to the require
section of your composer.json
file.
Migrations example
Warning! depth
attribute can not be unsigned!
Single tree migration:
Multiple tree migration:
Configuring
Optional you can setup Query for finding roots:
Query class:
Options
$treeAttribute = null
- setup tree attribute for multiple tree in table schema.$leftAttribute = 'lft'
- left attribute in table schema.$rightAttribute = 'rgt'
- right attribute in table schema.$depthAttribute = 'depth'
- depth attribute in table schema (note: it must be signed int).
Usage
Selection
Getting the root nodes
If you connect NestedSetsQueryTrait
, you can get all the root nodes:
Getting ancestors of a node
To get ancestors of a node:
To get parent of a node:
To get root of a node:
Getting descendants of a node
To get all the descendants of a node:
To populate children
relations for self and descendants of a node:
To get the children of a node:
Getting the leaves nodes
To get all the leaves of a node:
Getting the neighbors nodes
To get the next node:
To get the previous node:
Some checks
Modifications
To make a root node:
Note: if you allow multiple trees and attribute tree
is not set, it automatically takes the primary key value.
To prepend a node as the first child of another node:
To append a node as the last child of another node:
To insert a node before another node:
To insert a node after another node:
To delete a node with descendants: