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('刪除失敗!');
}
}