foreach($tmpData as $value){ $treeData[$value['id']] = $value; $plevel[$value['pid']][$value['id']] = 'END'; $clevel[$value['id']] = $value['pid']; } $this->treeData = &$treeData; $this->treePList = &$plevel; $this->treeCList = &$clevel; } /* * 解析分类列表 * *param $cataId int 要解析的主分类的编号 */ function parseNode($cataId=0){ $this->result = $this->treePList[$cataId]; if($this->result==null) die("Catagory id error"); $this->treeStr = $this->_doNode($this->result); $this->treeStr .= $this->_jsParse(); } function &_doNode(&$result){ $nstr = $estr = ''; foreach($result as $key=>$value){ if(isset($this->treePList[$key])){ $result[$key] = $this->treePList[$key]; $inner = $this->_doNode($result[$key]); $nstr .= $this->_parseNodeTpl($key, $inner); }else{ $estr .= $this->_parseElementTpl($key); } } return $nstr.$estr; } function &_parseNodeTpl($cataId, $inner){ $data = $this->treeData[$cataId]; $str = preg_replace(' ¦__id__ ¦', $data['id'], $this->blockTpl); $str = preg_replace(' ¦__name__ ¦', $data['name'], $str); $str = preg_replace(' ¦__image__ ¦', ($this->expand? $this->imgClose:$this->imgOpen), $str); $str = preg_replace(' ¦__open__ ¦', ($this->expand?'':'none'), $str); $str = preg_replace(' ¦__inner__ ¦', $inner, $str); return $str; } function _parseElementTpl($cataId){ $data = $this->treeData[$cataId]; $str = preg_replace(' ¦__id__ ¦', $data['id'], $this->elementTpl); $str = preg_replace(' ¦__name__ ¦', $data['name'], $str); $str = preg_replace(' ¦__image__ ¦', $this->imgLine, $str); return $str; } 希望看到更多更经典的开发技巧,请随时刷新《开发特区》栏目。
|
正在阅读:一棵php的类树(支持无限分类)一棵php的类树(支持无限分类)
2004-04-28 14:35
出处:CSDN
责任编辑:linjixiong
键盘也能翻页,试试“← →”键