예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Topic::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC], 'attributes' => ['created_at']]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'fid' => $this->fid, 'comment_count' => $this->comment_count, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $active = true)
 {
     $query = Topic::find();
     $active && $query->active();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'fid' => $this->fid, 'comment_count' => $this->comment_count, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content])->orderBy(['is_topic' => SORT_DESC]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * Finds the Topic model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Topic the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $type = 'topic', \Closure $func = null)
 {
     if ($id) {
         $model = $type == 'topic' ? Topic::find() : Comment::find();
         $model->andWhere(['id' => $id])->active();
         $func !== null && $func($model);
         $model = $model->one();
         if ($model !== null) {
             return $model;
         }
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
예제 #4
0
 /**
  * Finds the Topic model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Topic the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Topic::find()->where(['id' => $id])->active()->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }