backend/models/search/NewsSearch.php
/**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param array $params


Creates data provider instance with search query applied @param array $params
public function search($params)
    {
        $query = News::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> [
                'defaultOrder' => ['news_id'=>SORT_DESC],
                'attributes' => [
                    'news_id',
                    'news_status',
                    'news_created',
                    'news_updated',
                ]
            ],
            'pagination' => [
                'pageSize' => 100,
                'route'=>'news/index',
            ],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            'news_id' => $this->news_id,
            'news_status' => $this->news_status,
            'news_created' => $this->news_created,
            'news_updated' => $this->news_updated,
        ]);
        $query->andFilterWhere(['like', 'news_name', $this->news_name])
              ->andFilterWhere(['like', 'news_text', $this->news_text]);
        return $dataProvider;
    }
public function search ( $ params ) { $ query = News :: find ( ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'sort' => [ 'defaultOrder' => [ 'news_id' => SORT_DESC ] , 'attributes' => [ 'news_id' , 'news_status' , 'news_created' , 'news_updated' , ] ] , 'pagination' => [ 'pageSize' => 100 , 'route' => 'news/index' , ] , ] ) ; $ this -> load ( $ params ) ; if ( ! $ this -> validate ( ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'news_id' => $ this -> news_id , 'news_status' => $ this -> news_status , 'news_created' => $ this -> news_created , 'news_updated' => $ this -> news_updated , ] ) ; $ query -> andFilterWhere ( [ 'like' , 'news_name' , $ this -> news_name ] ) -> andFilterWhere ( [ 'like' , 'news_text' , $ this -> news_text ] ) ; return $ dataProvider ; }
Creates data provider instance with search query applied
 @param array $params
Creates data provider instance with search query applied @param array $params
// uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); //$query->addOrderBy(['news_created'=>SORT_DESC]);