本文以实例描述了ThinkPHP采用
1. 三级循环需要三维数组,实现代码如下:
function _MakeSonTree($pid) {
$map['pid'] = $pid;
$result = $this->where($map)->order('rank ASC')->findall();
if($result){
foreach ($result as $key => $value){
$title = $value['alias'];
$list[$title]['id']= $value['id'];
$list[$title]['pid']= $value['pid'];
$list[$title]['alias']= $value['alias'];
$list[$title]['title'] = $value['title'];
$list[$title]['level'] = $value['level'];
$list[$title]['state'] = $value['state'];
$list[$title]['rank'] = $value['rank'];
if($this->haschild($value['id'])){ //先判断是否有第三级子类,最后的数组形如$result['child']['grandchild'];
$list[$title]['grandchild']=$this->_MakeSonTree($value['id']);
}
}
}
return $list;
}
function haschild($id){
$result=D('LearningChannel')->where("pid=".$id)->find();
if($result){
return true;
}
else return false;
}
2.绑定volist标签:
3.模板部分: