Exemple #1
0
 /**
  * Deletes an existing Post model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $thread_id = $model->thread_id;
     $model->delete();
     $thread = Thread::findOne($thread_id);
     $thread->post_count = $thread->post_count - 1;
     $thread->update();
     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.'));
     return $this->redirect(['/forum/post/index']);
 }
 /**
  * Finds the Thread model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Thread the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Thread::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }