Giter VIP home page Giter VIP logo

yii2-tree's Introduction

Yii 2 Tree

Database tree structures management for Yii 2 framework

Latest Stable Version Total Downloads Latest Unstable Version License

Currently it's Nested Sets management extension based on:

Contents:

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist arogachev/yii2-tree

or add

"arogachev/yii2-tree": "*"

to the require section of your composer.json file.

Features

  • Basic actions with tree nodes: creating, renaming, moving, deleting
  • Saving state of nodes (opened / closed)
  • Links for updating node

Usage

Add this to application config:

'controllerMap' => [
    'tree' => 'arogachev\tree\controllers\TreeController',
],

Attach additional behavior along with NestedSetsBehavior to your model:

use arogachev\tree\behaviors\NestedSetsManagementBehavior;
/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        NestedSetsBehavior::className(),
        NestedSetsManagementBehavior::className(),
    ];
}

The last step is display widget:

use arogachev\tree\widgets\NestedSets;
use frontend\modules\department\models\Department;
<?= NestedSets::widget([
    'modelClass' => Department::className(),
]) ?>

Behavior configuration

nameAttribute - string, the name of attribute storing the name of node. Defaults to name.

saveState - boolean, save state of nodes (opened / closed). Defaults to false.

isOpenedAttribute - string, the name of attribute storing if the node opened or closed. Used together with saveState. Defaults to is_opened.

Widget configuration

modelClass - string, the full model class including namespace of managed model. Required.

updateUrl - string, url for updating model in separate page. Will be processed by yii\helpers\Url::to().

jsTreeOptions - array, options for JsTree widget. Example:

'jsTreeOptions' => [
    'clientOptions' => [
        'core' => [
            'strings' => [
                'New node' => 'Новый отдел',
            ],
        ],
    ],
],

yii2-tree's People

Contributors

arogachev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.