The thinkphp framework implements deletion and batch deletion, and thinkphp batch deletion.
This document describes how to use thinkphp to delete and batch delete data.
Expectation:
Forgive the bloggers for being so hasty in photo processing...
Still split in MVC mode:
First, View:
<Form action = "_ MODULE _/Admin/User/del" method = "get"> <tr> <th width = "4%"> <input type = "checkbox "name =" checkbox10 "id =" checkbox10 "> </th> <th width =" 13% "> User name </th> <th width =" 10% "> real name </th> <th width = "13%"> mobile phone number </th> <th width = "21%"> email </th> <th width = "11%"> registration time </th> <th width = "17%"> operation </th> </tr> <volist name = 'adminusers' id = 'vo'> <tr> <td> <input type = "checkbox" name = "id []" id = "checkbox" value = "{$ vo. id} "> <td> {$ vo. username} </td> <td> {$ vo. realname} </td> <td> {$ vo. telphone} </td> <td> {$ vo. email} </td> <td >{$ vo. resgistertime} </td> <a href = "_ MODULE _/Admin/User/modi/id/{$ vo. id} "> modify </a> <a href =" # "> </a> <a href =" _ MODULE _/Admin/User/del/id/ {$ vo. id} "> Delete </a> </td> </tr> </volist> </table> </div> <div class =" input-group pull-left form "> <button type =" submit "class =" btn-danger "> Delete </button> </div> </form>
It still uses the form value passing method, but this time it does not need to be verified because it is a direct processing of data rather than letting users input data, therefore, you don't have to worry about data legality. The model part is omitted. Here, we use a clever way to define name as an array. In the controller, we only need to judge whether the input id is an array, saving the trouble of separate writing.
Next is the Controller part.
Public function del () {// $ name = getActionName (); // Add $ adminUsersModel = D ("adminUsers") as a public function "); // obtain the operation object of the current module $ id =$ _ GET ['id']; // determine whether the id is an array or a value if (is_array ($ id )) {$ where = 'Id in ('. implode (',', $ id ). ')';} else {$ where = 'id = '. $ id;} // dump ($ where); $ list = $ adminUsersModel-> where ($ where)-> delete (); if ($ list! = False) {$ this-> success ("successfully deleted {$ list! ", U (" Admin/User/lists ");} else {$ this-> error ('deletion failed! ');}}
The above is all of the implementation processes. I don't know if this relatively clever method has been obtained by our friends?
Author: orange time