PHPackages                             open20/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. open20/yii2-tree-manager

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

open20/yii2-tree-manager
========================

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

2.0.2(5y ago)087BSD-3-ClausePHP

Since Apr 21Pushed 5y agoCompare

[ Source](https://github.com/regionelombardia-open20/yii2-tree-manager)[ Packagist](https://packagist.org/packages/open20/yii2-tree-manager)[ Docs](https://github.com/kartik-v/yii2-tree-manager)[ RSS](/packages/open20-yii2-tree-manager/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (18)Used By (0)

yii2-tree-manager
=================

[](#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) and [TreeView demonstration](http://demos.krajee.com/tree-manager-demo/treeview) or [TreeViewInput demonstration](http://demos.krajee.com/tree-manager-demo/treeview-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/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],
]);
```

License
-------

[](#license)

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

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 87.3% 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.

###  Release Activity

Cadence

Every ~132 days

Recently: every ~167 days

Total

16

Last Release

2049d ago

Major Versions

v1.1.2 → 2.0.02019-07-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/6eb97765ff9c2a6c83df362376ac9fe8f21e4ac4c3b65fd1e2380233178fe500?d=identicon)[open2.0](/maintainers/open2.0)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (186 commits)")[![muhammadcahya](https://avatars.githubusercontent.com/u/4241620?v=4)](https://github.com/muhammadcahya "muhammadcahya (4 commits)")[![yanhuixie](https://avatars.githubusercontent.com/u/1049615?v=4)](https://github.com/yanhuixie "yanhuixie (2 commits)")[![bubifengyun](https://avatars.githubusercontent.com/u/4437214?v=4)](https://github.com/bubifengyun "bubifengyun (2 commits)")[![makroxyz](https://avatars.githubusercontent.com/u/2069949?v=4)](https://github.com/makroxyz "makroxyz (2 commits)")[![waltermazza](https://avatars.githubusercontent.com/u/46817459?v=4)](https://github.com/waltermazza "waltermazza (2 commits)")[![kambizzandi](https://avatars.githubusercontent.com/u/6306448?v=4)](https://github.com/kambizzandi "kambizzandi (1 commits)")[![DoommeR](https://avatars.githubusercontent.com/u/10331178?v=4)](https://github.com/DoommeR "DoommeR (1 commits)")[![knjazevandr](https://avatars.githubusercontent.com/u/4064768?v=4)](https://github.com/knjazevandr "knjazevandr (1 commits)")[![linkaixiang4883](https://avatars.githubusercontent.com/u/28226678?v=4)](https://github.com/linkaixiang4883 "linkaixiang4883 (1 commits)")[![andrejlola](https://avatars.githubusercontent.com/u/2097312?v=4)](https://github.com/andrejlola "andrejlola (1 commits)")[![MariusRumpf](https://avatars.githubusercontent.com/u/2364426?v=4)](https://github.com/MariusRumpf "MariusRumpf (1 commits)")[![bookin](https://avatars.githubusercontent.com/u/537882?v=4)](https://github.com/bookin "bookin (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)")[![Edofre](https://avatars.githubusercontent.com/u/710429?v=4)](https://github.com/Edofre "Edofre (1 commits)")

---

Tags

nestedjquerysettreenestedsetajaxbootstraptreeviewhierarchykrajee

### Embed Badge

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

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

###  Alternatives

[kartik-v/yii2-tree-manager

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

156529.0k15](/packages/kartik-v-yii2-tree-manager)[kartik-v/yii2-editable

An enhanced editable widget for Yii 2.0 that allows easy editing of displayed data with numerous configuration possibilities.

1163.2M59](/packages/kartik-v-yii2-editable)[execut/yii2-widget-bootstraptreeview

Bootstrap Tree View widget wrapper for yii2

46170.2k](/packages/execut-yii2-widget-bootstraptreeview)[kartik-v/yii2-widget-rating

A Yii2 widget for the simple yet powerful bootstrap-star-rating plugin with fractional rating support (sub repo split from yii2-widgets)

444.1M8](/packages/kartik-v-yii2-widget-rating)[kartik-v/yii2-widget-timepicker

Enhanced Yii2 wrapper for the bootstrap timepicker plugin (sub repo split from yii2-widgets)

404.9M14](/packages/kartik-v-yii2-widget-timepicker)[kartik-v/yii2-sortable

Create sortable lists and grids using HTML5 drag and drop API for Yii 2.0.

433.8M13](/packages/kartik-v-yii2-sortable)

PHPackages © 2026

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