PHPackages                             geloft/yii2-tree-manager - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. geloft/yii2-tree-manager

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

geloft/yii2-tree-manager
========================

An enhanced tree management module with tree node selection and manipulation using nested sets.

00PHP

Since Nov 5Pushed 1y agoCompare

[ Source](https://github.com/geloft/yii2-tree-manager)[ Packagist](https://packagist.org/packages/geloft/yii2-tree-manager)[ RSS](/packages/geloft-yii2-tree-manager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

 [ ![Krajee Logo](https://camo.githubusercontent.com/4addfbb3869c3fc7d79befea4f06d9cf3655a686fb503df0da1d725859cfdef9/687474703a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f6b72616a65652d6c6f676f2d622e706e67) ](http://demos.krajee.com "Krajee Demos")
 yii2-tree-manager ---

=========================================================================================================================================================================================================================================================================================================================================================

 [![Donate](https://camo.githubusercontent.com/0336bc43d88554a3f2d6c74dddf312bc2c65c2eacca70d83ae40f5567098d00e/68747470733a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f646f6e6174652e706e67)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DTP3NZQ6G2AYU "Donate via Paypal") [![kartikv](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/kartikv "Buy me a coffee")

[](#------------------------yii2-tree-manager--------------------------)

[![Stable Version](https://camo.githubusercontent.com/f49ae3789bc7a3e7e857a0c02afdd96e4c895675c94232cadba3aabe21e0b879/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f762f737461626c65)](https://packagist.org/packages/kartik-v/yii2-tree-manager)[![Unstable Version](https://camo.githubusercontent.com/8b0012bd16dc0b3463ea240660e3a37792612874f262ed9b9b1f2f8a9651cbb9/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f762f756e737461626c65)](https://packagist.org/packages/kartik-v/yii2-tree-manager)[![License](https://camo.githubusercontent.com/cdad157fa5901c26ae5e2f27387d08aac69b587ef33ccfe349ce2f54345cebed/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f6c6963656e7365)](https://packagist.org/packages/kartik-v/yii2-tree-manager)[![Total Downloads](https://camo.githubusercontent.com/300d75a8fefb8a5514d40dbf0178844d1e7c6825c9ccf7cedcd897f733ed6860/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f646f776e6c6f616473)](https://packagist.org/packages/kartik-v/yii2-tree-manager)[![Monthly Downloads](https://camo.githubusercontent.com/9df1247049e019fb207000dda861e2ca4847980be52ca7d1e6bd63fc6d5c4379/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f642f6d6f6e74686c79)](https://packagist.org/packages/kartik-v/yii2-tree-manager)[![Daily Downloads](https://camo.githubusercontent.com/9116a72ae532abb419086c75cc2a7abd297d925e2730c9a186ddf340a28a8bb7/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d747265652d6d616e616765722f642f6461696c79)](https://packagist.org/packages/kartik-v/yii2-tree-manager)

An enhanced tree management module from Krajee with tree node selection and manipulation using nested sets. The extension features are listed below:

- A complete tree management solution which provides ability to manage hierarchical data stored using nested sets. Utilizes the [yii2-nested-sets](https://github.com/creocoder/yii2-nested-sets) extension to manage the tree structure in your database. Refer the documentation for yii2-nested-sets extension before you start using this module.
- A tree view built from scratch entirely without any third party plugins. The TreeView is designed using HTML5, jQuery &amp; CSS3 features to work along with Yii PHP framework.
- Styled with CSS3, includes jquery transitions and loading sections for ajax content, includes embedded alerts, and utilizes bootstrap css.
- Tree management feature options and modes:
    - View, edit, or administer the tree structure using **TreeView** widget as a selector and a dynamically rendered form to edit the tree node
    - The form works as both a detail view for the node OR as a management tool to add/edit/delete the node.
    - Form is rendered via ajax. It intelligently uses caching when the same node is clicked again (unless, the nodes are modified).
    - Unique Admin Mode for allowing administrator actions on tree.
    - Ability to add, edit, or delete tree nodes
    - Ability to reorder tree nodes (move up, down, left or right).
    - Configure tree node icons, styles, and ability to add checkboxes to tree nodes
    - i18N translations enabled across the module.
- Includes various jquery plugin events for advanced usage that are triggered on various tree manipulation actions.
- **Bonus:** Includes a **TreeViewInput** widget that allows you to use the treeview as an input widget. The TreeViewInput widget is uniquely designed by Krajee (using jQuery &amp; PHP with HTML5/CSS) to appear as a dropdown selection menu. It allows multiple selection or single selection of values/nodes from the tree.
- A Tree model that builds upon the yii2-nested-set model and is made to be easily extensible for various use cases. It includes prebuilt flags for each tree node. Check the Tree Model documentation for more.
- **active:** whether a tree node is active (if soft delete is enabled, the tree node will be just inactivated instead of deleting from database).
- **selected:** whether a tree node is selected by default.
- **disabled:** disables a tree node for editing or reorder
- **readonly:** a read only tree node that prevents editing, but can be reordered or moved up/down
- **visible:** whether a tree node is visible by default.
- **collapsed:** whether a tree node is collapsed by default.
- **movable\_u:** whether a tree node is allowed to be movable up.
- **movable\_d:** whether a tree node is allowed to be movable down.
- **movable\_l:** whether a tree node is allowed to be movable left.
- **movable\_r:** whether a tree node is allowed to be movable right.
- **removable:** whether a tree node is removable - will not be removed if children exist. If soft delete is enabled, then the node will be inactivated - else removed from database.
- **removable\_all:** whether a tree node is removable with children. If soft delete is enabled, then the node and its children will be inactivated - else removed from database.

The following important PHP classes are available with this module:

1. **kartik\\tree\\Module:** *Module*, allows you to configure the module. You must setup a module named `treemanager`. Refer documentation for details.
2. **kartik\\tree\\TreeView:** *Widget*, allows you to manage the tree in admin mode or normal user mode with actions and toolbar to add, edit, reorder, or delete tree nodes.
3. **kartik\\tree\\TreeViewInput:** *Widget*, allows you to use the treeview as a dropdown input either as a single select or multiple selection.
4. **kartik\\tree\\models\\Tree:** *Model*, the entire tree data structure that uses the Nested set behavior from [yii2-nested-sets](https://github.com/creocoder/yii2-nested-sets) to manage the tree nodes.
5. **kartik\\tree\\models\\TreeQuery:** *Query*, the query class as required for the Nested set model.
6. **kartik\\tree\\controllers\\NodeController:** *Controller*, the controller actions that manages the editing of each node for create, update, delete, or reorder (move).

Demo
----

[](#demo)

You can see detailed [documentation](http://demos.krajee.com/tree-manager), [API Code Documentation](https://docs.krajee.com/kartik-tree-treeview) and [TreeView demonstration](http://demos.krajee.com/tree-manager-demo/treeview) or [TreeViewInput demonstration](http://demos.krajee.com/tree-manager-demo/tree-view-input) on usage of the extension.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

> NOTE: Check the [composer.json](https://github.com/kartik-v/yii2-tree-manager/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.

Either run

```
$ php composer.phar require kartik-v/yii2-tree-manager "@dev"

```

or add

```
"kartik-v/yii2-tree-manager": "@dev"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### Step 1: Prepare Database

[](#step-1-prepare-database)

Create your database table to store the tree structure. You can do it in one of the following ways:

#### Option 1: Run DB Migrations

[](#option-1-run-db-migrations)

You can run the migrations script provided to create the database structure from your yii programming console:

```
php yii migrate/up --migrationPath=@vendor/kartik-v/yii2-tree-manager/src/migrations

```

#### Option 2: Executing SQL script

[](#option-2-executing-sql-script)

Alternatively, you can execute the SQL script to generate your DB structure. Copy and modify the `migrations/tree.sql` file (a MySQL example), to create the table `tbl_tree` (or for any table name you need).

> NOTE: You can add columns you need to this table, but you cannot skip/drop any of the columns mentioned in the script. You can choose to rename the `id`, `root`, `lft`, `rgt`, `lvl`, `name`, `icon`, `icon_type` columns if you choose to - but these must be accordingly setup in the module.

### Step 2: Setup Model

[](#step-2-setup-model)

Create your model for storing the tree structure extending `kartik\tree\models\Tree` class. You can alternatively build your own model extending from `yii\db\ActiveRecord` but modify it to use the `kartik\tree\models\TreeTrait`. You must provide the table name in the model. Optionally you can add rules, or edit the various methods like `isVisible`, `isDisabled` etc. to identify allowed flags for nodes.

So when extending from the `\kartik\tree\models\Tree`, you can set it like below:

```
namespace frontend\models;

use Yii;

class Tree extends \kartik\tree\models\Tree
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tbl_tree';
    }
}
```

Alternatively, you can configure your model to not extend from `kartik\tree\models\Tree` and instead implement and use the `kartik\tree\models\TreeTrait`:

```
namespace frontend\models;

use Yii;

class Tree extends \yii\db\ActiveRecord
{
    use kartik\tree\models\TreeTrait;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tbl_tree';
    }
}
```

### Step 3: Setup Module

[](#step-3-setup-module)

Configure the module named `treemanager` in the modules section of your Yii configuration file.

```
'modules' => [
   'treemanager' =>  [
        'class' => '\kartik\tree\Module',
        // other module settings, refer detailed documentation
    ]
]
```

### Step 4: Using TreeView Widget

[](#step-4-using-treeview-widget)

In your view files, you can now use the tree view directly to manage tree data as shown below:

```
use kartik\tree\TreeView;
echo TreeView::widget([
    // single query fetch to render the tree
    'query'             => Tree::find()->addOrderBy('root, lft'),
    'headingOptions'    => ['label' => 'Categories'],
    'isAdmin'           => false,                       // optional (toggle to enable admin mode)
    'displayValue'      => 1,                           // initial display value
    //'softDelete'      => true,                        // normally not needed to change
    //'cacheSettings'   => ['enableCache' => true]      // normally not needed to change
]);
```

### Step 5: Using TreeViewInput Widget

[](#step-5-using-treeviewinput-widget)

If you wish to use the tree input to select tree items, you can use the TreeViewInput widget as shown below. Normally you would use this as a dropdown with the `asDropdown` property set to `true`. If `asDropdown` is set to `false`, the treeview input widget will be rendered inline for selection.

```
use kartik\tree\TreeViewInput;
echo TreeViewInput::widget([
    // single query fetch to render the tree
    'query'             => Tree::find()->addOrderBy('root, lft'),
    'headingOptions'    => ['label' => 'Categories'],
    'name'              => 'kv-product',    // input name
    'value'             => '1,2,3',         // values selected (comma separated for multiple select)
    'asDropdown'        => true,            // will render the tree input widget as a dropdown.
    'multiple'          => true,            // set to false if you do not need multiple selection
    'fontAwesome'       => true,            // render font awesome icons
    'rootOptions'       => [
        'label' => '',
        'class'=>'text-success'
    ],                                      // custom root label
    //'options'         => ['disabled' => true],
]);
```

Contributors
------------

[](#contributors)

### Code Contributors

[](#code-contributors)

This project exists thanks to all the people who contribute. \[[Contribute](CONTRIBUTING.md)\]. [![](https://camo.githubusercontent.com/d1c514c125d930652742bc3de793b371756b26de9cb9848eca093456779bf95e/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f636f6e7472696275746f72732e7376673f77696474683d38393026627574746f6e3d66616c7365)](https://github.com/kartik-v/yii2-tree-manager/graphs/contributors)

### Financial Contributors

[](#financial-contributors)

Become a financial contributor and help us sustain our community. \[[Contribute](https://opencollective.com/yii2-tree-manager/contribute)\]

#### Individuals

[](#individuals)

[![](https://camo.githubusercontent.com/abe5fe8a1b47db7bc42236383d42dd39dbd65789583a5a2d3b1c8c21f7b8c738/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f696e646976696475616c732e7376673f77696474683d383930)](https://opencollective.com/yii2-tree-manager)

#### Organizations

[](#organizations)

Support this project with your organization. Your logo will show up here with a link to your website. \[[Contribute](https://opencollective.com/yii2-tree-manager/contribute)\]

[![](https://camo.githubusercontent.com/bb2c750099011994b62215237804b29871f699bf7cfbbba06402770f6d4536c4/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f302f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/0/website)[![](https://camo.githubusercontent.com/5f4af60c06591e0e56a2760a480efa8a0903710e29e07beaa7db055cd6aac3d7/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f312f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/1/website)[![](https://camo.githubusercontent.com/3dc055a4f9539c64099953ad2cc936c2cb3ccf1c3117457f114dceae09f0f4f0/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f322f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/2/website)[![](https://camo.githubusercontent.com/226296ecb1dbb21cde1e6864de13620120963d7f2abeccff73b96adb5d5bbf30/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f332f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/3/website)[![](https://camo.githubusercontent.com/c7293cb2ba165abe039cd8a7df99a78b835b4ec4f30c7201dd2fbc30eef111ee/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f342f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/4/website)[![](https://camo.githubusercontent.com/04a048701d2356aacb437e59c16216f60cec18f120363a5d7d000529aa87471e/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f352f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/5/website)[![](https://camo.githubusercontent.com/c7017b9750ff417d19e0ffd1102f99ae4f9c00f6ec5f8cd0241ef48923672970/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f362f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/6/website)[![](https://camo.githubusercontent.com/5e72e20ba0d33ba9f0b074374aa72bd9bb82e75ad8d2bf9f5e98021aa5a638b8/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f372f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/7/website)[![](https://camo.githubusercontent.com/db6c799c7a2b98db0328212b0d19b28adeaad1e52d4c8b0ea20197307e5da062/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f382f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/8/website)[![](https://camo.githubusercontent.com/5e628c730040c46833f586494284672ea7b9a3fb452782466896ca30959db80d/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f796969322d747265652d6d616e616765722f6f7267616e697a6174696f6e2f392f6176617461722e737667)](https://opencollective.com/yii2-tree-manager/organization/9/website)

License
-------

[](#license)

**yii2-tree-manager** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 86.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b95f059c082368514d759035a787724fa0dbe4501a893686db0fe2509535fb0?d=identicon)[geloft](/maintainers/geloft)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (197 commits)")[![muhammadcahya](https://avatars.githubusercontent.com/u/4241620?v=4)](https://github.com/muhammadcahya "muhammadcahya (4 commits)")[![makroxyz](https://avatars.githubusercontent.com/u/2069949?v=4)](https://github.com/makroxyz "makroxyz (2 commits)")[![bubifengyun](https://avatars.githubusercontent.com/u/4437214?v=4)](https://github.com/bubifengyun "bubifengyun (2 commits)")[![geloft](https://avatars.githubusercontent.com/u/101716956?v=4)](https://github.com/geloft "geloft (2 commits)")[![yanhuixie](https://avatars.githubusercontent.com/u/1049615?v=4)](https://github.com/yanhuixie "yanhuixie (2 commits)")[![Edofre](https://avatars.githubusercontent.com/u/710429?v=4)](https://github.com/Edofre "Edofre (1 commits)")[![jafaripur](https://avatars.githubusercontent.com/u/5066430?v=4)](https://github.com/jafaripur "jafaripur (1 commits)")[![kambizzandi](https://avatars.githubusercontent.com/u/6306448?v=4)](https://github.com/kambizzandi "kambizzandi (1 commits)")[![alexforte](https://avatars.githubusercontent.com/u/12466062?v=4)](https://github.com/alexforte "alexforte (1 commits)")[![linkaixiang4883](https://avatars.githubusercontent.com/u/28226678?v=4)](https://github.com/linkaixiang4883 "linkaixiang4883 (1 commits)")[![MariusRumpf](https://avatars.githubusercontent.com/u/2364426?v=4)](https://github.com/MariusRumpf "MariusRumpf (1 commits)")[![monkeywithacupcake](https://avatars.githubusercontent.com/u/7316730?v=4)](https://github.com/monkeywithacupcake "monkeywithacupcake (1 commits)")[![nicomollet](https://avatars.githubusercontent.com/u/108828?v=4)](https://github.com/nicomollet "nicomollet (1 commits)")[![okplatova](https://avatars.githubusercontent.com/u/5129094?v=4)](https://github.com/okplatova "okplatova (1 commits)")[![srnden](https://avatars.githubusercontent.com/u/16322716?v=4)](https://github.com/srnden "srnden (1 commits)")[![syedmuneer](https://avatars.githubusercontent.com/u/19424588?v=4)](https://github.com/syedmuneer "syedmuneer (1 commits)")[![tombouctou](https://avatars.githubusercontent.com/u/529780?v=4)](https://github.com/tombouctou "tombouctou (1 commits)")[![TonisOrmisson](https://avatars.githubusercontent.com/u/6357451?v=4)](https://github.com/TonisOrmisson "TonisOrmisson (1 commits)")[![knjazevandr](https://avatars.githubusercontent.com/u/4064768?v=4)](https://github.com/knjazevandr "knjazevandr (1 commits)")

### Embed Badge

![Health badge](/badges/geloft-yii2-tree-manager/health.svg)

```
[![Health](https://phpackages.com/badges/geloft-yii2-tree-manager/health.svg)](https://phpackages.com/packages/geloft-yii2-tree-manager)
```

###  Alternatives

[mirazmac/dotenvwriter

A PHP library to write values to .env (DotEnv) files

19129.3k7](/packages/mirazmac-dotenvwriter)[joegreen0991/config

Config component based on laravel's

233.3k](/packages/joegreen0991-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
