PHP code example of kasoft / yii2-jstree
1. Go to this page and download the library: Download kasoft/yii2-jstree 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/ */
kasoft / yii2-jstree example snippets
$tree = new \studio255\jstree\JsTree([
'jsonUrl' => '/my-json-url/data',
]);
public function actionIndex()
{
$tree = new \studio255\jstree\JsTree([
'modelName' => 'backend\\models\\YourModel',
'modelPropertyId' => 'id',
'modelPropertyParentId' => 'parent_id',
'modelPropertyPosition' => 'position',
'modelPropertyName' => 'name',
'modelFirstParentId' => null,
'modelPropertyType' => 'type',
'controllerId' => 'index',
'jstreeDiv' => '#jstree',
'jstreeIcons' => false,
'jstreePlugins' => ['contextmenu', 'dnd'],
'jstreeContextMenue' => [
'remove' => ['text' => 'Delete', 'icon' => 'fa fa-trash'],
'edit' => ['text' => 'Edit', 'icon' => 'fa fa-pencil'],
'create' => [
'text' => 'Create new',
'icon' => 'fa fa-plus',
'type' => 'online',
'submenu' => [
['text' => 'New offline node', 'icon' => 'fa fa-cloud', 'type' => 'offline'],
['text' => 'New online node', 'icon' => 'fa fa-cloud-bolt', 'type' => 'online'],
],
],
'rename' => ['text' => 'Rename', 'icon' => 'fa fa-i-cursor'],
],
'jstreeType' => [
'#' => ['max_children' => -1, 'max_depth' => -1, 'valid_children' => -1, 'icon' => 'fa fa-list'],
'default' => ['icon' => 'fa fa-question'],
],
'jstreeMsg' => [
'confirmdelete' => 'Are you sure you want to delete this item?',
'nothere' => 'Not allowed at this position.',
],
]);
return $this->render('index');
}