/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Stadium::find(); $country = new Country(); $stadiumTable = Stadium::tableName(); $countryTable = Country::tableName(); $query->joinWith(['country' => function ($query) use($countryTable) { $query->from(['country' => $countryTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); // enable sorting for the related columns $addSortAttributes = ["country.name"]; foreach ($addSortAttributes as $addSortAttribute) { $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]]; } if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(["{$stadiumTable}.id" => $this->id, 'spectators' => $this->spectators]); $query->andFilterWhere(['like', "{$stadiumTable}.name", $this->name])->andFilterWhere(['like', 'country.name', $this->getAttribute('country.name')]); return $dataProvider; }