php下拉选项的批量操作的实现代码

前端之家收集整理的这篇文章主要介绍了php下拉选项的批量操作的实现代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

实现功能,操作项可以单独删除,批量项可以批量删除,批量显示,隐藏(改广告的数据库的status_is的值);

1.视图关键点:

代码如下:
Box" name="id[]" value="id?>">
id?>

代码如下:

代码如下:
/*单个删除*/

2.控制器:

代码如下:
/**
* 批量操作
*
*/
public function actionBatch ()
{
if (XUtils::method() == 'GET') { //单个删除是get方式
$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','只支持POST,GET数据');
}
empty($ids) && XUtils::message('error','未选择记录'); switch ($command) { case 'adDelete':
parent::_acl('ad_delete');
parent::_adminiLogger(array('catalog'=>'delete','intro'=>'删除广告,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'=>'广告状态变更为显示,ID:'.$ids));
parent::_verify(new Ad(),'verify',array ('ad' )); break;
case 'adUnVerify':
parent::_acl('ad_verify');
parent::_adminiLogger(array('catalog'=>'delete','intro'=>'广告状态变更为隐藏,ID:'.$ids));
parent::_verify(new Ad(),'unVerify',array ('ad' ));
break;
default:
throw new CHttpException(404,'错误的操作类型:' . $command);
break;
} }

父类删除函数

代码如下:
protected function _delete ($model = null,$id = '',$redirect = 'index',$attach = null,$pkField = 'id')
{
if ($attach) { //如果有附件要删除广告的图片
$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 . ')' ));
//刷新缓存
self::_refreshCache($model);
$this->redirect($redirect);
}

代码如下:
protected function _verify ($model = null,$type = 'verify',$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);
//刷新缓存
self::_refreshCache($model);
$this->redirect($redirect);
}

原文链接:https://www.f2er.com/php/25602.html

猜你在找的PHP相关文章