mirror of
https://github.com/Oreolek/yii2-nested-sets.git
synced 2024-07-01 05:55:00 +03:00
1.5 KiB
1.5 KiB
Nested Sets Behavior for Yii 2
Introduction
The nested sets behavior for the Yii framework.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require creocoder/yii2-nested-sets "dev-master"
or add
"creocoder/yii2-nested-sets": "dev-master"
to the require section of your composer.json
file.
Configuring
First you need to configure model as follows:
use creocoder\nestedsets\NestedSetsBehavior;
class Tree extends \yii\db\ActiveRecord
{
public function behaviors() {
return [
NestedSetsBehavior::className(),
];
}
public function transactions()
{
return [
self::SCENARIO_DEFAULT => self::OP_ALL,
];
}
public static function find()
{
return new TreeQuery(get_called_class());
}
}
Second you need to configure query model as follows:
use creocoder\nestedsets\NestedSetsQueryBehavior;
class TreeQuery extends \yii\db\ActiveQuery
{
public function behaviors() {
return [
NestedSetsQueryBehavior::className(),
];
}
}
Usage
TBD.