PHP code example of devgroup / yii2-jstree-widget
1. Go to this page and download the library: Download devgroup/yii2-jstree-widget library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devgroup / yii2-jstree-widget example snippets
<?= TreeWidget::widget([
'treeDataRoute' => ['/menu/getTree'],
'reorderAction' => ['/menu/treeReorder'],
'treeType' => TreeWidget::TREE_TYPE_NESTED_SET, //important config option
'contextMenuItems' => [
'edit' => [
'label' => 'Edit',
'action' => ContextMenuHelper::actionUrl(
['/menu/edit']
),
]
],
])
php
use devgroup\JsTreeWidget\actions\AdjacencyList\FullTreeDataAction;
use devgroup\JsTreeWidget\actions\AdjacencyList\TreeNodesReorderAction;
use devgroup\JsTreeWidget\actions\AdjacencyList\TreeNodeMoveAction;
...
public function actions()
{
return [
'getTree' => [
'class' => FullTreeDataAction::class,
'className' => Menu::class,
],
'menuReorder' => [
'class' => TreeNodesReorderAction::class,
'className' => Menu::class,
],
'menuChangeParent' => [
'class' => TreeNodeMoveAction::class,
'className' => Menu::class,
],
];
}
php
<?= TreeWidget::widget([
'treeDataRoute' => ['/menu/getTree', 'selected_id' => $parent_id],
'reorderAction' => ['/menu/menuReorder'],
'changeParentAction' => ['/menu/menuChangeParent'],
'treeType' => TreeWidget::TREE_TYPE_ADJACENCY,
'contextMenuItems' => [
'open' => [
'label' => 'Open',
'action' => ContextMenuHelper::actionUrl(
['/menu/list'],
['parent_id']
),
],
'edit' => [
'label' => 'Edit',
'action' => ContextMenuHelper::actionUrl(
['/menu/edit']
),
]
],
])