无限分类的删除
public function _before_delete($option){
if (is_array($option['where']['cate_id'])) {
$arr = explode(",",$option['where']['cate_id'][1]);
foreach ($arr as $key => $v) {
$concateids = $this->childrenid($v);
}
$concateids = array_unique($concateids);
$concateids = implode(",",$concateids);
if ($concateids) {
$this->execute("delete from ar_category where cate_id in ($concateids)");
}
}else{
$childrenids = $this->childrenid($option['where']['cate_id']);
$childrenids = implode(",",$childrenids);
if ($childrenids) {
$this->execute("delete from ar_category where cate_id in ($childrenids)");
}
}
}
首先执行一个钩子函数,也就是在删除前先执行上面的方法。在这里我们可以输出下$option
和$option['where']['cate_id']
,判断条件就是我们当前删除的是一条还是多条。
public function childrenid($cateid){
$data = $this->select();
return $this->getchildrenid($data,$cateid);
}
public function getchildrenid($data,$parentid){
static $ret = array();
foreach ($data as $key => $v) {
if ($v['parentid']==$parentid) {
$ret[] = $v['cate_id'];
$this->getchildrenid($data,$v['cate_id']);
}
}
return $ret;
}