Пример #1
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 /**
  * Deletes an existing Thread 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);
     if ($model->user_id === Yii::$app->user->id || $model->board['user_id'] == Yii::$app->user->id) {
         $board_id = $model->board_id;
         Post::deleteAll(['thread_id' => $model->id]);
         $model->delete();
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.'));
         return $this->redirect(['/forum/board/view', 'id' => $board_id]);
     } else {
         throw new ForbiddenHttpException('You are not allowed to perform this action.');
     }
 }
Пример #3
0
 /**
  * Deletes an existing Thread 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);
     if ($model->user_id === Yii::$app->user->id || $model->board['user_id'] == Yii::$app->user->id) {
         $board_id = $model->board_id;
         Post::deleteAll(['thread_id' => $model->id]);
         return $model->delete();
     } else {
         throw new ForbiddenHttpException('You are not allowed to perform this action.');
     }
 }