?? ???? ?? ??
?? ???? ?? ??
???? ???? ?? ????. ?? ?? ??? ? ?? ????? ???? ???. ?? ?. cate ???? controll public function del($id){
$cata=D('cate');
$childids=$cata->getchild($id);
$childids=implode(',',$childids);
if($cata->delete($childids)){
$this->success('刪除欄目成功!',U('index'));
}else{
$this->error('刪除欄目失?。?#39;);
}
}
catemodel ?? layer public function getchild($cateid){
$data=$this->select();
return $this->getchildids($data,$cateid);
}
public function getchildids($data,$cateid){
static $res=array();
$res[]=$cateid;
foreach ($data as $k => $v) {
if ($v['pid']==$cateid) {
$res[]=$v['id'];
$this->getchildids($data,$v['id']);
}
}
return array_unique($res);
}
let 's with rayers
public function getchild($cateid){ $data=$this->select(); return $this->getchildids($data,$cateid); }??? getchild ???? ??? ID? ?? ? ?? ????? ?????. getchildids ???? ???? ID? ?????.
public function getchildids($data,$cateid){ static $res=array(); $res[]=$cateid; foreach ($data as $k => $v) { if ($v['pid']==$cateid) { $res[]=$v['id']; $this->getchildids($data,$v['id']); } } return array_unique($res); }$res=array();??? ?????. $res[]=$cateid; ? ??? ID? ???? ? ?????. foreach? ???? ?????. pid? ?? ID? ??? ?? ID? ????? ?????. ? ?? $res[] ? ???? ????? ?? ?????.
return array_unique($res); Eileen? ? ??? ???? array_unique? ?? ??? ?????.
$childids=implode(',',$childids); ??? ???? ???? ??? ? ????.
??? ?? ???? ?? ?? ??? ?? ??? ? ????.