/
Ladlen
/
news2
Обзор
Документация
Войти
/
Ladlen
/
news2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
models/NewsSearch.php
76 строк
2 KB
Dolgov Dmitriy
news pagination, main page
11 июн 2017, 17:14
11 июн 2017, 17:14
87f6ce6
Код
Авторство
О чём код?
<?php namespace app\models; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use app\models\News; /** * NewsSearch represents the model behind the search form about `app\models\News`. */ class NewsSearch extends News { /** * @inheritdoc */ public function rules() { return [ [['id', 'created_at', 'updated_at'], 'integer'], [['title', 'body'], 'safe'], ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * @param int $pageSize * * @return ActiveDataProvider */ public function search($params, $pageSize) { $query = News::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => $pageSize, ], ]); $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; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'body', $this->body]); return $dataProvider; } }