• Stars
    star
    150
  • Rank 238,707 (Top 5 %)
  • Language
    PHP
  • License
    Other
  • Created over 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An advanced tree management module using nested sets for Yii 2.

Krajee Logo
yii2-tree-manager

Donate       kartikv

Stable Version Unstable Version License Total Downloads Monthly Downloads Daily Downloads

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 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 & 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 & 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 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

You can see detailed documentation, API Code Documentation and TreeView demonstration or TreeViewInput demonstration on usage of the extension.

Installation

The preferred way to install this extension is through composer.

NOTE: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki 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

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

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

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

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

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

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

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' => '<i class="fa fa-tree"></i>', 
        'class'=>'text-success'
    ],                                      // custom root label
    //'options'         => ['disabled' => true],
]);

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

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

More Repositories

1

bootstrap-fileinput

An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.
JavaScript
5,330
star
2

bootstrap-star-rating

A simple yet powerful JQuery star rating plugin with fractional rating support.
JavaScript
1,049
star
3

yii2-widgets

Collection of useful widgets for Yii Framework 2.0
PHP
560
star
4

yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
PHP
557
star
5

yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
CSS
322
star
6

yii2-widget-fileinput

An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)
PHP
231
star
7

dependent-dropdown

JQuery plugin that enables to add and control multi level dependent dropdown lists.
JavaScript
182
star
8

yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
PHP
163
star
9

yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
CSS
161
star
10

bootstrap-popover-x

Bootstrap popover extended with modal properties and more.
116
star
11

yii2-editable

An enhanced editable widget for Yii 2.0 that allows easy editing of displayed data with html inputs, widgets and more.
PHP
113
star
12

yii2-widget-datepicker

Enhanced Yii2 wrapper for the bootstrap datepicker plugin (sub repo split from yii2-widgets)
PHP
113
star
13

yii2-widget-datetimepicker

Enhanced Yii2 wrapper for the bootstrap datetimepicker plugin (sub repo split from yii2-widgets)
PHP
105
star
14

bootstrap-tabs-x

Bootstrap tabs supercharged with various alignment and styling options
100
star
15

yii2-builder

Build forms (single or tabular) easily for Yii Framework 2.0.
PHP
100
star
16

bootstrap-checkbox-x

An extended checkbox plugin for bootstrap with three states and additional styles.
JavaScript
95
star
17

yii2-date-range

A Date Range Picker for Bootstrap useful for reports and filtering.
JavaScript
92
star
18

yii2-social

A Yii2 module for embedding social plugins and widgets.
PHP
92
star
19

yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
PHP
90
star
20

yii2-helpers

Collection of useful helper functions for Yii Framework 2.0
PHP
88
star
21

strength-meter

A dynamic strength meter for password input validation with various configurable options.
JavaScript
88
star
22

yii2-widget-depdrop

Widget that enables setting up dependent dropdowns with nested dependencies (sub repo split from yii2-widgets).
PHP
83
star
23

yii2-password

Useful password strength validation utilities for Yii Framework 2.0
PHP
74
star
24

yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
PHP
74
star
25

yii2-icons

Set of icon frameworks for easy use in Yii Framework 2.0
CSS
71
star
26

yii2-detail-view

Various enhancements to the Yii 2 Detail View with ability to edit data and manage styles using BS3.
PHP
71
star
27

yii2-krajee-base

Foundation classes and components used by Krajee Yii2 extensions
PHP
67
star
28

yii2-app-practical

Yii 2 Practical Project Template (based on advanced app)
PHP
66
star
29

yii2-widget-activeform

Enhanced Yii2 active-form and active-field with full bootstrap styling support (sub repo split from yii2-widgets).
PHP
63
star
30

yii2-datecontrol

Date control module allowing separation of date formats for View & Model for Yii Framework 2.0.
PHP
54
star
31

yii2-dialog

An extension that wraps bootstrap3-dialog for Yii 2.0 framework
PHP
49
star
32

yii2-widget-typeahead

Enhanced Yii2 wrapper for the Twitter Typeahead plugin (sub repo split from yii2-widgets).
JavaScript
44
star
33

php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.
JavaScript
44
star
34

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)
PHP
44
star
35

yii2-sortable

Create sortable lists and grids using HTML5 drag and drop API for Yii 2.0.
JavaScript
43
star
36

yii2-widget-timepicker

Enhanced Yii2 wrapper for the bootstrap timepicker plugin (sub repo split from yii2-widgets).
PHP
41
star
37

krajee-markdown-editor

A Boostrap styled markdown editor that offers configurable toolbar, live preview, export, fullscreen mode, and more features
JavaScript
41
star
38

mpdf

Fork of the mPDF latest DEV library (unofficial) with composer and packagist support.
PHP
40
star
39

yii2-widget-switchinput

A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes & radios as toggle switches (sub repo split from yii2-widgets)
PHP
38
star
40

yii2-widget-growl

A widget to generate growl based notifications using bootstrap-growl plugin (sub repo split from yii2-widgets)
PHP
38
star
41

yii2-widget-sidenav

An enhanced side navigation menu styled for bootstrap (sub repo split from yii2-widgets)
PHP
36
star
42

bootstrap-fileinput-samples

Example files for the bootstrap-fileinput plugin
35
star
43

yii2-app-practical-a

Yii 2 Practical-A ProjectTemplate (based on advanced app)
PHP
34
star
44

yii2-widget-colorinput

An enhanced Yii2 widget encapsulating the HTML 5 color input (sub repo split from yii2-widgets)
JavaScript
32
star
45

yii2-tabs-x

Extended bootstrap tabbed navigation widget for Yii 2.0 with various alignment and styling options.
PHP
30
star
46

yii2-app-practical-b

Yii 2 Practical Application Template (based on basic app)
PHP
30
star
47

yii2-widget-alert

An extended bootstrap alert and alert block widget for Yii2 (sub repo split from yii2-widgets)
PHP
28
star
48

yii2-nav-x

Extended bootstrap Nav widget with submenu option for Yii 2.
PHP
28
star
49

yii2-widget-spinner

A widget to render animated CSS3 loading spinners with VML fallback for IE (sub repo split from yii2-widgets)
JavaScript
28
star
50

yii2-slider

A slider input with orientations, range selections and more features based on bootstrap-slider.
PHP
28
star
51

yii2-ipinfo

An IP address information display widget for Yii 2 with country flag and geo position info
PHP
27
star
52

yii2-money

An advanced money mask input for Yii 2.0 styled for Bootstrap 3
JavaScript
26
star
53

yii2-checkbox-x

Extended checkbox widget for bootstrap with three states and additional styles for Yii 2.
PHP
25
star
54

yii2-field-range

Easily manage Yii 2 ActiveField ranges (from/to) with Bootstrap 3.x / 4.x addons markup and more.
PHP
24
star
55

yii2-popover-x

Extended bootstrap popover for Yii 2.0 with modal behavior and various styling options.
PHP
23
star
56

yii2-sortable-input

An input widget based on yii2-sortable extension allowing to store/save the sort order.
PHP
23
star
57

yii2-number

A number format mask control and input for Yii2 Framework
PHP
22
star
58

yii2-editors

Yii2 editor widgets Summernote and Codemirror.
PHP
21
star
59

yii2-validators

Enhanced Yii2 model validator components / utilities for Yii2 Framework
PHP
20
star
60

yii2-widget-rangeinput

An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)
PHP
19
star
61

yii2-widget-touchspin

Yii2 wrapper for the bootstrap-touchspin spinner component (sub repo split from yii2-widgets)
JavaScript
18
star
62

yii2-widget-affix

A scrollspy and affixed enhanced navigation to highlight page sections (sub repo split from yii2-widgets)
PHP
15
star
63

yii2-dropdown-x

An extended bootstrap dropdown widget for Yii 2 with submenu drilldown.
PHP
15
star
64

yii2-label-inplace

A form enhancement widget for in-field label support.
JavaScript
11
star
65

yii2-bootstrap4-dropdown

Enhanced Bootstrap 4 dropdown widget for Yii2 framework with nested submenu support.
PHP
9
star
66

yii2-word-report

Make reports in Yii2 with Microsoft Word Templates
PHP
9
star
67

yii2-report

Create reports out of MS Word templates using PHP-Reports api.
PHP
8
star
68

yii2-context-menu

Yii 2 context menu extension with Bootstrap 3 styling.
PHP
7
star
69

yii2-filesystem

File system handling utilities and components
PHP
6
star
70

yii2-mail-manager

Mailer management module with queuing and administration
PHP
6
star
71

yii2-rest-api

Yii2 Rest API Template
PHP
5
star
72

yii2-mailer

A mail management module for Yii 2.0 with ability to manage mail queues, templates, and more.
4
star
73

yii2-mxgraph

Yii2 port of the MxGraph library
3
star
74

yii2-google-docs

2
star
75

yii2-query-filter

Advanced Yii2 query filters via an easy user interface
1
star
76

kartik-v

1
star
77

yii2-bootstrap5-dropdown

Enhanced Bootstrap 5 dropdown widget for Yii2 framework with nested submenu support
PHP
1
star