admin/comm/function.php 函数中填写
/**
* 无限级分类
* @param $aray[数据循环数据],$pid[父级ID],$level[循环级数],$html[定义HTML]
* @return boolean
* @author 神夜 QQ:56437999
*/
function catetree ($array,$pid=0,$level=0,$html='|--'){
$arr = array();
foreach($array as $v){
if($v['pid']==$pid){
$v['level'] = $level + 1;
$v['html'] = str_repeat($html, $level);
$arr[] = $v;
$arr = array_merge($arr,catetree($array,$v['cid'],$level+1,$html));
}
}
return $arr;
}
//控制器中调用
public function cate_add(){
$cate = M('pcate')->select();
$list = catetree($cate);
$this->assign('list',$list);
$this->display();
}
//视图中显示
<select name="pid" class="input-text select" style="width:30%">
<option value="0">顶级分类</option>
<option value="{$data['cid']}">{$data['html']}{$data['catename']}</option>
</select>