#1 yuyu775
在model层 lib_catalog.php 中//递归查询栏目分类列表
public function getCatalogList($id=0,$level=0)
{
$conditions = array('pid'=>$id);
$results = $this->findAll($conditions);
$catlist = array();
for($i=0;$i < $level *2 - 1;$i++){
$str .=" ";
}
if($level++){$str .= "┝";};
foreach ($results as $cat){
$id = $cat['cid'];
$name = $str.$cat['cname'];
$seq = $cat['seq'];
$value = array('cid'=>$id,'cname'=>$name,'seq'=>$seq);
$catlist[] = $value;
$catlist = array_merge($catlist,$this->getCatalogList($id,$level));
}
return $catlist;
}
在controller层 catalog.php 中
public function catalogList(){
$catalogObj = spClass("lib_catalog");
$this->results = $catalogObj->getCatalogList();
//dump($this->results);
$this->display("admin/catalog.html");
}
Catalog 数据表结构
cid 主键 自动递增
pid //父ID
cname // 栏目名称
seq //排列顺序
2010-07-01 17:47:36