wodrow/yii2-wwtree

另一款分类树编辑管理工具

Installs: 79

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.2 2019-11-07 03:59 UTC

This package is auto-updated.

Last update: 2024-05-08 15:13:38 UTC


README

使用方式

安装

composer require wodrow/yii2-wwtree dev-master
模型
public function behaviors()
{
    return [
        'tree' => [
            'class' => \wodrow\yii2wwtree\TreeBehavior::class,
            'primaryKeyAttribute' => 'your_pk_id_filed_name',
            'parentKeyAttribute' => 'your_parent_id_filed_name',
            'nameKeyAttribute' => 'your_name_filed_name',
            'sortKeyAttribute' => 'your_sort_filed_name',
            'iconKeyAttribute' => 'your_icon_filed_name',
            'iconColorKeyAttribute' => 'your_icon_color_filed_name',
        ],
    ];
}
视图
<?=wodrow\yii2wwtree\TreeWidget::widget([
    'treeModelClass' => "your model class",
    // 'custom_field_view' => "@your/extend/view",
    // 'ajaxUrl' => "",
]) ?>

注意

数据表必须要有id, pid(父级), name, sort, icon, icon_color这六个字段,字段名可以是TreeBehavior配置的字段名;
其他字段根据需要自己添加, 在custom_field_view视图里可以处理添加的字段,使用它生成的模型。

如果使用ajaxUrl,推荐在控制器添加actions

public function actions()
{
    return [
        ...,
        'to-your-ajax-url' => [
            'class' => \wodrow\yii2wwtree\SearchAction::class,
            'searchClass' => TestTree::class,
            'idKeyAttr' => 'your id field key',
            'textKeyAttr' => 'your text field key',
        ],
    ];
}

截图

kiEcj0.png