无限极分类删除父节点时将父节点的所有子节点删除,该代码基于thinkPHP3.2.3,在model中使用,通过parentlist查询所有子ID,然后删除
- <?php
- function delArea($id){
- $depth['CONCAT(',',parentidlist,',')']=array('like','%,'.$id.',%');
- $ids = $this->where($depth)->field('id')->select();
- //查询需要删除的所有子id
- if($ids){
- $arr=array();
- foreach($ids as $key=>$vo){
- $arr[]=$vo['id'];
- }
- }
- if($arr){
- $str=implode(',', $arr);
- $depth['id']=array('in',$str);
- $update['status']=0;
- $res=$this->where($depth)->save($update);
- if($res){
- echo '删除成功';
- }else{
- echo '删除失败';
- }
- }else{
- echo '删除失败';
- }
- }
复制代码 |