第一步:在components 新建Tree.php文件
第二步:在Controller的actionIndex方法里面执行create方法<?php class Tree { /** * @param array $param * $param string $pid * return array $param */ static public $treeList=array(); public function create($data,$pid=0){ foreach($data as $key=>$value){ if($value['pid']==$pid){ self::$treeList[]=$value; unset($data[$key]); self::create($data,$value['id']); } } return self::$treeList; } }
public function actionIndex(){
parent::_acl();
$school = new Schoolattr;
$where = "select * from un_school_attr where countries_type = 1";
$schoolList = $school->findAllBySql($where);
$tree = new Tree;
$schoolList = $tree::create($schoolList);
print_r($schoolList); exit;
}