Code for batch operations of php drop-down options

Source: Internet
Author: User

Implement functions. Operation items can be deleted separately. Batch items can be deleted, displayed in batches, and hidden (change the status_is value of the AD database );

1. View key points:

Copy codeThe Code is as follows:
<Td> <input type = "checkbox" name = "id []" value = "<? Php echo $ row-> id?> ">
<? Php echo $ row-> id?> </Td>

Copy codeThe Code is as follows:
<Div class = "fixsel">
<Input type = "checkbox" name = "chkall" id = "chkall" onclick = "checkAll (this. form, 'id')"/>
<Label for = "chkall"> select all </label>
<Select name = "command">
<Option> Select Operation </option>
<Option value = "adDelete"> Delete </option>
<Option value = "adVerify"> display </option>
<Option value = "adUnVerify"> hide </option>
</Select>
<Input id = "submit_maskall" class = "button confirmSubmit" type = "submit" value = "submit" name = "maskall"/>
</Div>

Copy codeThe Code is as follows:
/* Single Delete */

<A href = "<? Php echo $ this-> createUrl ('batch', array ('command' => 'addelete', 'id' => $ row-> id)?> "Class =" confirmSubmit ">

2. Controller:

Copy codeThe Code is as follows:
/**
* Batch operation
*
*/
Public function actionBatch ()
{
If (XUtils: method () = 'get') {// a single Delete is a GET method.
$ Command = trim ($ _ GET ['command']);
$ Ids = intval ($ _ GET ['id']);
} Else
If (XUtils: method () = 'post '){
$ Command = trim ($ _ POST ['command']);
$ Ids = $ _ POST ['id'];
Is_array ($ ids) & $ ids = implode (',', $ ids );
} Else {
XUtils: message ('errorback', 'only POST, GET data ');
}
Empty ($ ids) & XUtils: message ('error', 'no record selected ');

Switch ($ command ){

Case 'addelete ':
Parent: _ acl ('ad _ delete ');
Parent: _ adminiLogger (array ('catalog '=> 'delete', 'intro' => 'delete AD, ID:'. $ ids ));
Parent: _ delete (new Ad (), $ ids, array ('ad'), array ('Attach _ file '));
Break;
Case 'adverify ':
Parent: _ acl ('ad _ verify ');
Parent: _ adminiLogger (array ('catalog '=> 'delete', 'intro' =>'. The ad status changes to display, ID: '. $ ids ));
Parent: _ verify (new Ad (), 'verify ', $ ids, array ('ad '));

Break;
Case 'adunverify ':
Parent: _ acl ('ad _ verify ');
Parent: _ adminiLogger (array ('catalog '=> 'delete', 'intro' =>'. The ad status changes to hidden, ID: '. $ ids ));
Parent: _ verify (new Ad (), 'unverify ', $ ids, array ('ad '));
Break;
Default:
Throw new CHttpException (404, 'wrong operation type: '. $ command );
Break;
}

}

The deletion function of the parent class:

Copy codeThe Code is as follows:
Protected function _ delete ($ model = null, $ id = '', $ redirect = 'index', $ attach = null, $ pkField = 'id ')
{
If ($ attach) {// if there is an attachment to delete the image of the advertisement
$ Data = $ model-> findAll ($ pkField. 'In (: id) ', array (': id' => $ id ));
Foreach (array) $ data as $ row ){
Foreach (array) $ attach as $ value ){
If (! Empty ($ row [$ value]) {
@ Unlink ($ row [$ value]);
}
}
}
}
$ Result = $ model-> deleteAll (array ('condition '=> 'Id IN ('. $ id .')'));
// Refresh the cache
Self: _ refreshCache ($ model );
$ This-> redirect ($ redirect );
}

Copy codeThe Code is as follows:
Protected function _ verify ($ model = null, $ type = 'verify ', $ id = '', $ redirect = 'index', $ cdField = 'status _ is ', $ pkField = 'id ')
{
$ Criteria = new CDbCriteria ();
$ Criteria-> condition = $ pkField. 'IN ('. $ id .')';
$ ShowStatus = $ type = 'verify '? 'Y': 'n ';
$ Result = $ model-> updateAll (array ($ cdField => $ showStatus), $ criteria );
// Refresh the cache
Self: _ refreshCache ($ model );
$ This-> redirect ($ redirect );
}

Related Article

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.