ThinkPHP实现批量删除教程Php

元气糖发布于:2019-1-22 1082

    ThinkPHP实现批量删除数据原理很简单,只需在模板页面里面写上<input name='id[]' type='checkbox' value='{$vo.id}' class="noborder">这样传过来就是一个数组,action的删除函数del()如下:

/**
**删除函数支持删除多条和一个 **/ 
function del(){
  //dump($_GET['id']);
  //$name = strtolower($_GET['_URL_'][0]); //获取当前模块名
  $name = $this->getActionName();
  $model = D($name);//获取当期模块的操作对象
  $id = $_GET['id'];
  //判断id是数组还是一个数值
  if(is_array($id)){
    $where = 'id in('.implode(',',$id).')';
  }else{
    $where = 'id='.$id;
  }
  //dump($where);
  $list=$model->where($where)->delete();
  if($list!==false) {
    $this->success("成功删除{$list}条!");
  }else{
    $this->error('删除失败!');
  }
}



http://www.virplus.com/thread-26.htm
转载请注明:2019-1-22 于 VirPlus 发表

推荐阅读
最新回复 (0)

    ( 登录 ) 后,可以发表评论!

    返回