2017 © Pedro Peláez
 

yii2-extension yii2-ext-for-work-nested-set

Include widget and behavior for edit Nested Set tree

image

ale10257/yii2-ext-for-work-nested-set

Include widget and behavior for edit Nested Set tree

  • Sunday, December 24, 2017
  • by AlexeyKulagin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 63 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

Extension for edit Nested Set tree

Include widget and behavior for edit Nested Set tree, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

composer require ale10257/yii2-ext-for-work-nested-set "dev-master"

or add, (*4)

"ale10257/yii2-ext-for-work-nested-set": "dev-master"

to the require section of your composer.json file., (*5)

Capabilities

  1. Generating a menu tree as a table (use Nested Set tree), (*6)

  2. Drag & Drop rows table, (*7)

  3. Save result in DB, (*8)

Example table before move, (*9)

before move, (*10)

Move, (*11)

move, (*12)

After move, (*13)

after move, (*14)

Important

Only siblings elements can be dragged!!!, (*15)

Usage

Model, (*16)

Set up the model as here: https://github.com/creocoder/yii2-nested-sets and determine the constant SITE_ROOT_NAME and behaviors, (*17)

 NestedSetsBehavior::className(),
                'treeAttribute' => 'tree',
            ],
            [
                'class' => ChangeTreeBehavior::className(),
                'rootSite' => SITE_ROOT_NAME
            ]
        ];
    }
      
//...
?>

View index.php for Category, (*18)

//...
    <?php if($data) : ?>
        <div class="category-index">
            <h1><?= Html::encode($this->title) ?></h1>
                <?= $this->render('tree', ['data' => $data]) ?>
        </div>
    <?php endif ?>
//...

View tree.php, (*19)

 [
            'data' => $data,
            // action for ajax request for edit tree
            'urlChangeTree' => Url::to(['/admin/category/update-tree']), 
            'urlUpdateTree' => Url::to(['/admin/category/update']),
            'urlDeleteTree' => Url::to(['/admin/category/delete']),
            'urlAddItem' => Url::to(['/admin/category/create']),
            // name field in your table for view
            'fieldForTitleItem' => 'name',
        ]
    ]); 
?>

Controller, (*20)

render('index', [
            'data' => $category->getTree(),
        ]);
    }
//...  
    //accepts the ajax request  
    public function actionUpdateTree()
    {
        if (Yii::$app->request->isAjax) {
            $model = new Category();
            $post = Yii::$app->request->post();
            return $this->renderPartial('tree', ['data' => $model->updateTree($post)]);
        }
        return Yii::$app->request->referrer;
    }    
//...
?>

The Versions

24/12 2017

dev-master

9999999-dev

Include widget and behavior for edit Nested Set tree

  Sources   Download

MIT

The Requires

 

by Alexey Kulagin

yii2 nested set dnd