【问题标题】:how to create treeview in yii framework如何在 yii 框架中创建树形视图
【发布时间】:2014-04-24 16:01:15
【问题描述】:

我想创建一个获取的树视图 来自数据库的数据,之后 按父字段排序 所以包括表字段:

product_category_id

product_category_parent_id

产品类别名称

被提及的记录 按名称“product_category_parent_id” 是 0 没有任何根,当它希望有任何 身份证号码/号码,父母身份证应该在这个地方 所以表的结构必须发送到 查看:

<ul><li><ul><li></li></ul></li></ul>

【问题讨论】:

    标签: php view yii tree treeview


    【解决方案1】:

    有一个如何创建CTreeView的例子

    private function generateTree($models)
    {
        $data = array();
    
        foreach ($models as $category) {
            $data[$category->id] = array(
                'id'   => $category->id,
                'text' => '<a href="/admin/catalog/category/id/'.$category->id.'">'.$category->category_name.'</a>',
    
            );
            foreach ($category->goods as $item) {
                $data[$category->id]['children'][$item->id] = array(
                    'id'   => $item->id,
                    'text' =>  '<a href="/admin/catalog/item/id/'.$item->id.'">'.$item->article.'</a>',
                    'expanded' => false,
                );
            }
    
        }
        return $data;
    }
    

    在视图中

    $this->widget('CTreeView', array('data' => $data,'persist'=>'cookie'));
    

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      相关资源
      最近更新 更多