1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-07-03 06:55:00 +03:00
yii2-nested-sets/README.md

72 lines
1.4 KiB
Markdown

# Nested Sets Behavior for Yii 2
The nested sets behavior for the Yii framework.
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require creocoder/yii2-nested-sets "dev-master"
```
or add
```json
"creocoder/yii2-nested-sets": "dev-master"
```
to the require section of your `composer.json` file.
## Configuring
First you need to configure model as follows:
```php
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:
```php
use creocoder\nestedsets\NestedSetsQueryBehavior;
class TreeQuery extends \yii\db\ActiveQuery
{
public function behaviors() {
return [
NestedSetsQueryBehavior::className(),
];
}
}
```
## Usage
TBD.
[![PayPal - The safer, easier way to pay online!](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WJYG53DVUAALL)