Solved Filter Multiple Rows Gridview by id Yii2.

Hi, i have run a gridview correctly, and i have the following doubt, when i want to filters records by id, for example i write 1 and work fine, but want to filter 2 o more records when i write 1,3 always brings me the firts id.

As I can filter multiple records by id.

thks,

Wilmer.

Model Horarios Search:




<?php


namespace backend\models;


use Yii;

use yii\base\Model;

use yii\data\ActiveDataProvider;


/**

 * HorariosSearch represents the model behind the search form about `frontend\models\Horarios`.

 */

class HorariosSearch extends Horarios

{

    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            [['id'], 'safe' ],

            [['nombre', 'tipo'], '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

     *

     * @return ActiveDataProvider

     */

    public function search($params)

    {

        $query = Horarios::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'pagination' => [

                'pageSize' => 10,

            ],

        ]);


        if (!($this->load($params) && $this->validate())) {

            return $dataProvider;

        }


        $query->andFilterWhere([

            'id' => $this->id,

        ]);


        $query->andFilterWhere(['like', 'nombre', $this->nombre])

            ->andFilterWhere(['like', 'tipo', $this->tipo]);


        return $dataProvider;

    }

}



Controller Horarios:




    public function actionIndex()

    {

        $searchModel = new HorariosSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }



You have to customize your search function. For example, explode the string on the “,” and find the records by all id’s.

Could you give me an example you would appreciate, since I’m new to yii2 and php.

Solved.