PHP code example of rezident / yii2-nested-set-plus

1. Go to this page and download the library: Download rezident/yii2-nested-set-plus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rezident / yii2-nested-set-plus example snippets


use kgladkiy\behaviors\NestedSetBehavior;
use kgladkiy\behaviors\NestedSetQuery; 

class Category extends ActiveRecord
{
    public function behaviors()
    {
        return [
            [
                'class' => NestedSetBehavior::className(),
                // 'rootAttribute' => 'root',
                // 'levelAttribute' => 'level',
                // 'hasManyRoots' => true
            ],
        ];
    }

    public static function find()
    {
        return new NestedSetQuery(get_called_class());
    }
}

use kgladkiy\widgets\NestedList;

echo NestedList::widget([
    'items' => $treeData, // $treeData = Category::find()->tree();
    'actions' => true, // set to false for disable 'edit' and 'delete' buttons
]);
sh
php composer.phar