PHPackages                             andipas/yii2-gtreetable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. andipas/yii2-gtreetable

ActiveYii2-extension

andipas/yii2-gtreetable
=======================

yii2-gtreetable is an extension of Yii 2 Framework, which is wrapper for bootstrap-gtreetable plug-in, on the other hand it provides functionality which allows to save the nodes states into database.

v1.1.1-alpha(11y ago)014MITPHP

Since Nov 4Pushed 9y ago1 watchersCompare

[ Source](https://github.com/andipas/yii2-gtreetable)[ Packagist](https://packagist.org/packages/andipas/yii2-gtreetable)[ Docs](https://github.com/gilek/yii2-gtreetable)[ RSS](/packages/andipas-yii2-gtreetable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Yii2-GTreeTable
===============

[](#yii2-gtreetable)

Yii2-GTreeTable is extension of Yii 2 framework which is wrapper for [bootstrap-gtreetable](https://github.com/gilek/bootstrap-gtreetable) plugin, on the other hand provides support to server side application. With fixes;

Thanks to software it's possible to map actual state of nodes to data base.

Test available on [demo project](http://gtreetable2.gilek.net).

[![](https://camo.githubusercontent.com/777c42c9d8ec28c1625b1c1fff76234215d235f4f3a608eb5bc2ae7bef3481f4/687474703a2f2f67696c656b2e6e65742f696d616765732f677474322d64656d6f2e706e67)](https://camo.githubusercontent.com/777c42c9d8ec28c1625b1c1fff76234215d235f4f3a608eb5bc2ae7bef3481f4/687474703a2f2f67696c656b2e6e65742f696d616765732f677474322d64656d6f2e706e67)

Installation
------------

[](#installation)

Installation is realized by [Composer](https://getcomposer.org).

In the console write:

```
composer require gilek/yii2-gtreetable "*"

```

or add following line in `require` section of `composer.json` file.

```
"gilek/yii2-gtreetable": "*"

```

One more thing, don't forget about the `fxp/composer-asset-plugin` installation:

```
composer global require fxp/composer-asset-plugin "1.0.0"

```

Minimal configuration
----------------------------------------------------------------------

[](#minimal-configuration)

> Note: You can also use a migrate file and omit following two steps: `yii migrate --migrationPath=/vendor/gilek/yii2-gtreetable/migrations`

1. Create table to store nodes:

```
CREATE TABLE `tree` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `root` INT(10) UNSIGNED DEFAULT NULL,
  `lft` INT(10) UNSIGNED NOT NULL,
  `rgt` INT(10) UNSIGNED NOT NULL,
  `level` SMALLINT(5) UNSIGNED NOT NULL,
  `type` VARCHAR(64) NOT NULL,
  `name` VARCHAR(128) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `root` (`root`),
  KEY `lft` (`lft`),
  KEY `rgt` (`rgt`),
  KEY `level` (`level`)
);
```

2. Add main node:

```
INSERT INTO `tree` (`id`, `root`, `lft`, `rgt`, `level`, `type`, `name`) VALUES (1, 1, 1, 2, 0, 'default', 'Main node');
```

3. Create new [active record](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html) model, based on table described in point 1. It's important that model extend `gilek\gtreetable\models\TreeModel` class:

```

```

4. Create new controller or add to existing one following actions:

```

```

Configuration
-------------

[](#configuration)

### Actions

[](#actions)

All actions from `gilek\gtreetable\actions` location have properties:

- `afterAction` (callback(`gilek\gtreetable\models\TreeModel` $model)) function triggered directly after code responsible for action task i.e. after node deleting,
- `$afterRun` (callback) - function triggered after run the action,
- `beforeAction` (callback(`gilek\gtreetable\models\TreeModel` $model)) - function triggered directly before code responsible for action task i.e. before node deleting,
- `$beforeRun` (callback) - function triggered before run the action. More info in [yii\\base\\Action class documentation](http://www.yiiframework.com/doc-2.0/yii-base-action.html#afterRun%28%29-detail).

Example of use, checking access to authorization unit:

```
