gilek/yii2-gtreetable
最新稳定版本:v1.1.3
Composer 安装命令:
composer require gilek/yii2-gtreetable
包简介
yii2-gtreetable is an extension of Yii 2 Framework, which is wrapper for bootstrap-gtreetable plug-in, on the other hand it provides functionality which allows to save the nodes states into database.
README 文档
README
Yii2-GTreeTable is extension of Yii 2 framework which is wrapper for bootstrap-gtreetable plugin, on the other hand provides support to server side application.
Thanks to software it's possible to map actual state of nodes to data base.
Test available on demo project.
Installation
Installation is realized by Composer.
In the console write:
composer require gilek/yii2-gtreetable "*"
or add following line in require section of composer.json file.
"gilek/yii2-gtreetable": "*"
One more thing, don't forget about the fxp/composer-asset-plugin installation:
composer global require fxp/composer-asset-plugin
Minimal configuration
Note: You can also use a migrate file and omit following two steps:
yii migrate --migrationPath=<app_dir>/vendor/gilek/yii2-gtreetable/migrations
- Create table to store nodes:
CREATE TABLE `tree` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `root` INT(10) UNSIGNED DEFAULT NULL, `lft` INT(10) UNSIGNED NOT NULL, `rgt` INT(10) UNSIGNED NOT NULL, `level` SMALLINT(5) UNSIGNED NOT NULL, `type` VARCHAR(64) NOT NULL, `name` VARCHAR(128) NOT NULL, PRIMARY KEY (`id`), KEY `root` (`root`), KEY `lft` (`lft`), KEY `rgt` (`rgt`), KEY `level` (`level`) );
- Add main node:
INSERT INTO `tree` (`id`, `root`, `lft`, `rgt`, `level`, `type`, `name`) VALUES (1, 1, 1, 2, 0, 'default', 'Main node');
- Create new active record model, based on table described in point 1.
It's important that model extend
gilek\gtreetable\models\TreeModelclass:
<?php class Tree extends \gilek\gtreetable\models\TreeModel { public static function tableName() { return 'tree'; } } ?>
- Create new controller or add to existing one following actions:
<?php use app\models\Tree; class TreeController extends \yii\web\Controller { public function actions() { return [ 'nodeChildren' => [ 'class' => 'gilek\gtreetable\actions\NodeChildrenAction', 'treeModelName' => Tree::className() ], 'nodeCreate' => [ 'class' => 'gilek\gtreetable\actions\NodeCreateAction', 'treeModelName' => Tree::className() ], 'nodeUpdate' => [ 'class' => 'gilek\gtreetable\actions\NodeUpdateAction', 'treeModelName' => Tree::className() ], 'nodeDelete' => [ 'class' => 'gilek\gtreetable\actions\NodeDeleteAction', 'treeModelName' => Tree::className() ], 'nodeMove' => [ 'class' => 'gilek\gtreetable\actions\NodeMoveAction', 'treeModelName' => Tree::className() ], ]; } public function actionIndex() { return $this->render('@gilek/gtreetable/views/widget', ['options'=>[ // 'manyroots' => true // 'draggable' => true ]]); } } ?>
Configuration
Actions
All actions from gilek\gtreetable\actions location have properties:
-
afterAction(callback(gilek\gtreetable\models\TreeModel$model)) function triggered directly after code responsible for action task i.e. after node deleting, -
$afterRun(callback) - function triggered after run the action, -
beforeAction(callback(gilek\gtreetable\models\TreeModel$model)) - function triggered directly before code responsible for action task i.e. before node deleting, -
$beforeRun(callback) - function triggered before run the action. More info in yii\base\Action class documentation.
Example of use, checking access to authorization unit:
<?php [ 'nodeCreate' => [ 'class' => 'gilek\gtreetable\actions\NodeCreateAction', 'treeModelName' => Tree::className(), 'beforeRun' => function() { if (!Yii::$app->user->can('Node create')) { throw new \yii\web\ForbiddenHttpException(); } } ] ?>
$treeModelName(TreeModel) - reference to model data extending formgilek\gtreetable\models\TreeModel(see Minimal configuration point 1).
Model
Support of tree structure in data base is based on Nested set model.
Abstract class gilek\gtreetable\models\TreeModel provides Nested set model on PHP side. It defines validation rules and other required methods. Its configuration can by adjusted by parameters:
-
$depthAttribute(string) - column name storing level of node. Defualtlevel, -
$leftAttribute(string) - column name storing left value. Defaultlft, -
$nameAttribute(string) - column name storing label of node. Defualtname, -
$rightAttribute(string) - column name storing left value. Defaultrgt, -
$treeAttribute(string) - column name storing reference to main element ID. Defaultroot, -
$typeAttribute(string) - column name storing type of node. Defaulttype.
View
gilek\gtreetable\views\widget view class consists configuration of CUD operation with reference to nodes source. There is no necessity to use it, but it can be very helpful in simple projects.
Class may be adjusted by properties:
-
$controller(string) - controller name where the actions are defined (see Minimal configuration point 4). By default is getting the controller name where thegilek\gtreetable\views\widgetview was triggered, -
$options(array) - options supplied directly to bootstrap-gtreetable plugin, -
$routes(array) - in the case when particular nodes are located in different containers or its name is different in relation to presented in point 4 of the chapter Minimal configutarion, then it's necessary to define it,
Following example shows structure of data:
<?php [ 'nodeChildren' => 'controllerA/source', 'nodeCreate' => 'controllerB/create', 'nodeUpdate' => 'controllerC/update', 'nodeDelete' => 'controllerD/delete', 'nodeMove' => 'controllerE/move' ] ?>
$title(string) - define site title, when view is called directly from action level (see Minimal configuration point 4).
Widget
The main task of gilek\gtreetable\Widget widget is generate parameters to bootstrap-gtreetable plugin and adding required files.
When container in not available he also response for creating it. Class has following properties:
-
$assetBundle(AssetBundle) - parameter allows to overflow the mainAssetBundlepacket i.e.Asset, -
$columnName(string) - table column name. Default value isNamewhich is getting from translation file, -
$htmlOptions(array) - html options of container, they are rendering in the moment of its creation (parameter$selectorset onnull), -
$options(array) - options supplied directly to bootstrap-gtreetable plugin, -
$selector(string) - jQuery selector indicated on tree container (<table>tag). When parameter is set onnull, table will be automatically created. Defaultnull.
Limitations
Yii2-GTreeTable use Nested Set behavior for Yii 2 extension, which in for the moment (Januray 2015) has some limitation regarding ordering main elements (nodes which level = 0).
In case of adding or moving node as the main node, then it will be located after last element in this level. Therefore order of displayed main nodes may not have the same mapping in data base.
gilek/yii2-gtreetable 适用场景与选型建议
gilek/yii2-gtreetable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.85k 次下载、GitHub Stars 达 41, 最近一次更新时间为 2014 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tree」 「extension」 「yii2」 「nested」 「gtreetable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gilek/yii2-gtreetable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gilek/yii2-gtreetable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gilek/yii2-gtreetable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
jsTree widget for yii2
A custom URL rule class for Yii 2 which allows to create translated URL rules
Doctrine2 behavior traits - slowhop fork
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 11.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-06