/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Thread::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, 'block_id' => $this->block_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Deletes an existing Board 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) { $forum_url = $model->forum['forum_url']; Thread::deleteAll(['board_id' => $model->id]); $model->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.')); return $this->redirect(['/forum/forum/update', 'id' => $forum_url, 'action' => 'board']); } else { throw new ForbiddenHttpException('You are not allowed to perform this action.'); } }
protected function newThread($id) { $newThread = new Thread(); if ($newThread->load(Yii::$app->request->post())) { $newThread->board_id = $id; $newThread->save(); Yii::$app->db->createCommand()->update('{{%forum_board}}', ['updated_at' => time(), 'updated_by' => Yii::$app->user->id], 'id=:id', [':id' => $id])->execute(); $this->refresh(); } return $newThread; }
/** * 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.'); } }