/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Seo::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id])->andFilterWhere(['index' => $this->index])->andFilterWhere(['follow' => $this->follow])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
public function loadMetaTags($preferUrlWithParams = true) { $request = Yii::$app->getRequest(); $path = '/' . $request->getPathInfo(); $url = $request->getUrl(); $preferOrder = $preferUrlWithParams ? 'DESC' : 'ASC'; $seo = SeoRecords::find()->orWhere(['url' => $path])->orWhere(['url' => $url])->orderBy("url {$preferOrder}")->one(); if ($seo) { foreach ($this->fields as $field) { if (isset($seo->{$field})) { $this->{$field} = $seo->{$field}; } } } }