Home  >  Article  >  Backend Development  >  Implementation code of batch operation of php drop-down options_PHP tutorial

Implementation code of batch operation of php drop-down options_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:59862browse

Implementation code of batch operation of php drop-down options_PHP tutorial

Implement the function, operation items can be deleted individually, batch items can be deleted in batches, displayed in batches, hidden (change the value of status_is of the advertising database);

1. View key points:

Copy code The code is as follows:


   id?>

Copy code The code is as follows:


   
         
                                                                                                                                                    < ;option value="adVerify">Show
                                                                                                                                      "submit_maskall" class="button confirmSubmit" type="submit" value="Submit" name="maskall" />
                                                 




Copy code

The code is as follows:

/*Single delete*/


2. Controller:

Copy code

The code is as follows:


/**
* Batch operation
*
*/
public function actionBatch ()
{
if (XUtils::method() == 'GET') { //Single deletion is get Method
          $command = trim($_GET['command']);                                                                                                                                                                                                                                      . ) == 'POST') {
                   $command = trim($_POST['command']);                             $ids = $_POST['id']; = implode(',', $ids);
                                                                           ) && XUtils::message('error', 'No record selected'); ad_delete');
parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'Delete ad, ID:'.$ids));
parent::_delete (new Ad(), $ids, array ('ad' ), array ('attach_file' ));
                                                         ;
                parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'Advertising status changed to display, ID:'.$ids)); new Ad(), 'verify', $ids, array ('ad' ));

break;
case 'adUnVerify':
parent::_acl('ad_verify');
              parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'Advertising status changed to hidden, ID:'.$ids)); Ad(), 'unVerify', $ids, array ('ad' ));
                         break;
                   break;



Delete function of parent class:




Copy code

The code is as follows:

protected function _delete ($model = null, $id = '', $redirect = 'index', $attach = null, $pkField = 'id')
{
if ($ attach) { //If there is an attachment, delete the advertising image
$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 . ')' ));
                                                                                                                                                                     }







Copy code

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 cache
self::_refreshCache($model);
$this->redirect($redirect);
}







http://www.bkjia.com/PHPjc/824851.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/824851.html

implements functions, operation items can be deleted individually, batch items can be deleted in batches, displayed in batches, hidden (change the database of advertisements The value of status_is); 1. View key points: Copy code...