Php implementation code for batch operations with drop-down options. Implement functions. Operation items can be deleted separately. batch items can be deleted, displayed in batches, and hidden (the status_is value of the database for modifying the advertisement). 1. View key points: Copy the code generation.
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:
The code is as follows:
Id?>
The code is as follows:
Select all
Select operation Delete Display Hide
The code is as follows:
/* Single delete */
CreateUrl ('batch', array ('command' => 'addelete', 'id' => $ row-> id)?> "Class =" confirmSubmit ">
2. controller:
The 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:
The 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 );
}
The 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 );
}
Transform (change the status_is value of the ad database); 1. View key points: generation...