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 );
}