Home > php教程 > php手册 > body text

ThinkPHP实现批量删除数据的代码实例

WBOY
Release: 2016-06-13 09:32:10
Original
840 people have browsed it

ThinkPHP实现批量删除数据原理很简单,只需在模板页面里面写上这样传过来就是一个数组,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('删除失败!');
  }
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!