/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } else { if ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'Delete': foreach ((array) $ids as $id) { $adModel = AdPosition::model()->findByPk($id); if ($adModel) { $adModel->delete(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index')); }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 AdPosition::model()->deleteAll($criteria); break; case 'show': //显示 AdPosition::model()->updateAll(['status' => AdPosition::STATUS_SHOW], $criteria); break; case 'hide': //隐藏 AdPosition::model()->updateAll(['status' => AdPosition::STATUS_HIDE], $criteria); break; default: $this->controller->message('error', Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
public function init() { parent::init(); //广告位 $positions = AdPosition::model()->findAll(); foreach ((array) $positions as $pv) { $this->_adposition[''] = "==请选择广告位=="; $this->_adposition[$pv->id] = $pv->position; } }
public function init() { parent::init(); //广告位 $positions = AdPosition::model()->findAll(array('condition' => 'status = "' . AdPosition::STATUS_SHOW . '"')); foreach ((array) $positions as $pv) { $this->_adposition[''] = "==请选择广告位=="; $this->_adposition[$pv->id] = $pv->title; } }
/** * 判断数据是否存在 * * return \$this->model */ public function loadModel() { if ($this->model === null) { if (isset($_GET['id'])) { $this->model = AdPosition::model()->findbyPk($_GET['id']); } if ($this->model === null) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } } return $this->model; }