コード例 #1
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     //$this->loadModel($id)->delete();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     //if(!isset($_GET['ajax']))
     //	$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
     $model = $this->loadModel($id);
     $sql = 'ALTER TABLE ' . BaseCccdCompanyData::model()->tableName() . ' DROP `' . $model->varname . '`';
     if ($model->dbConnection->createCommand($sql)->execute()) {
         $model->delete();
     }
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_POST['ajax'])) {
         $this->redirect(array('admin'));
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }