yii框架分类树扩展示例

2020-02-10 14:12:41丽君

下拉框方式

<?php $this->widget('ext.tree.widgets.TreeWidget',array(
            'dataProvider'  => $cate,           // 传递数据
            'pid'           => 'pid',                   // 设置父ID           
            'formatParam'   => 'name',                  // 设置格式化字段
            'treeType'      => false,                   // 输出树格式
            'selectClass'  => 'class="span11"',         // 设置下拉框样式
             'defaultSelectValue' => array(             // 设置下拉框的默认值和选项
                    0 , '≡ 作为一级栏目 ≡'
             ),
        )); ?>

TreeWidget.php


<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Tree
 *
 * @author 汪嘉诚
 * @email 819434425@qq.com
 * 
 * 表格方式调用
    <?php $this->widget('ext.tree.widgets.TreeWidget',array(
        'dataProvider'  => $dataProvider,           // 传递数据
        'pid'           => 'pid',                   // 设置层级关系id
        'tableClass'    => 'items table table-striped table-bordered table-condensed',  // 表格样式
        'formatParam'   => 'name',                  // 设置格式化字段