The thinkphp framework implements deletion and batch deletion, and thinkphp batch deletion.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.