コード例 #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
ファイル: PostSearch.php プロジェクト: rocketyang/iisns
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'user_id' => $this->user_id, 'thread_id' => $this->thread_id]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
コード例 #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);
     $board_id = $model->board_id;
     if ($model->user_id === Yii::$app->user->id || $model->board['user_id']) {
         Post::deleteAll(['thread_id' => $model->id]);
         $model->delete();
         Yii::$app->getSession()->setFlash('success', 'Delete successfully.');
     } else {
         throw new ForbiddenHttpException('You are not allowed to perform this action.');
     }
     return $this->redirect(['/forum/board/view', 'id' => $board_id]);
 }
コード例 #4
0
ファイル: ThreadController.php プロジェクト: richardcj/iisns
 /**
  * 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);
     $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]);
 }