Download the PHP package paulzi/yii2-materialized-path without Composer
On this page you can find all versions of the php package paulzi/yii2-materialized-path. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paulzi/yii2-materialized-path
More information about paulzi/yii2-materialized-path
Files in paulzi/yii2-materialized-path
Package yii2-materialized-path
Short Description Materialized Path Behavior for Yii2
License MIT
Informations about the package yii2-materialized-path
Yii2 Materialized Path Behavior
Implementation of materialized path 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
Single tree migration:
Multiple tree migration:
Configuring
Optional you can setup Query for finding roots:
Query class:
Sortable Behavior
This behavior attach SortableBehavior. You can use its methods (for example, reorder()).
Options
$pathAttribute = 'path'
- setup path attribute in table schema.$depthAttribute = 'depth'
- setup depth attribute in table schema.$itemAttribute = null
- setup item attribute in table schema for get path path, if the value is not set - using the primary key.$treeAttribute = null
- setup tree attribute for multiple tree, when item attribute is not primary key.$sortable = []
- SortableBehavior settings - see paulzi/yii2-sortable.$delimiter = '/'
- delimiter of path items.$rootDepthValue = 0
- setup value of$depthAttribute
for root nodes.
Usage
Selection
Getting the root nodes
If you connect MaterializedPathQueryTrait
, 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:
Reorder children:
Updating from 1.x to 2.x
- Move attributes
sortAttribute
,step
intosortable
attribute. - Change namespace from
paulzi\materializedpath
topaulzi\materializedPath
. - Include
paulzi\yii2-sortable
(composer update
).