Пример #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)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if ($model = $this->loadModel($id)) {
             if ($model->delete()) {
                 Yii::log("Delete record " . print_r($model->attributes, true), 'info');
                 TagsPosts::deleteTagsPost($id);
                 CategoriesPosts::deleteCategory($id);
             }
         }
         // 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('index'));
         }
     } else {
         Yii::log("Invalid request. Please do not repeat this request again.");
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Пример #2
0
 public static function deleteCategory($post_id)
 {
     CategoriesPosts::model()->deleteAll("post_id = {$post_id}");
 }