Code Example of Realizing Batch Deleting Data by ThinkPHP

  • 2021-07-07 06:38:10
  • OfStack

The principle of ThinkPHP to delete data in batches is very simple, just write it in the template page < input name='id[]' type='checkbox' value='{$vo.id}' class="noborder" > This is an array, and the delete function del () of action is as follows:


/**
** The delete function supports deleting multiple and 1 A 
**/
function del(){
 //dump($_GET['id']);
 //$name = strtolower($_GET['_URL_'][0]); // Get the current module name 
 $name = $this->getActionName();
 $model = D($name);// Gets the operation object of the current module 
 $id = $_GET['id'];
 // Judge id Is it an array or 1 Numeric value 
 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(" Deleted successfully {$list} Article! ");
 }else{
  $this->error(' Delete failed! ');
 }
}

Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "smarty Template Introduction Basic Tutorial" and "PHP Template Technology Summary".

Hope that this article is based on ThinkPHP framework of PHP programming help.


Related articles: