/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MArticle::find()->where(['gh_id' => Yii::$app->user->getGhid()])->orderBy('article_id DESC'); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['article_id' => $this->article_id, 'photo_id' => $this->photo_id, 'show_cover_pic' => $this->show_cover_pic, 'create_time' => $this->create_time]); $query->andFilterWhere(['like', 'gh_id', $this->gh_id])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'digest', $this->digest])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'content_source_url', $this->content_source_url]); return $dataProvider; }
/** * Finds the MArticle model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return MArticle the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MArticle::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getArticles() { return $this->hasMany(MArticle::className(), ['photo_id' => 'photo_id']); }
public function getArticle() { return $this->hasOne(MArticle::className(), ['article_id' => 'article_id']); }