Created
January 17, 2016 05:28
-
-
Save c006/28a0f0f544a0bcaee6ca to your computer and use it in GitHub Desktop.
Yii2 Model Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function search($params) | |
{ | |
$query = ShippingRulesModel::find(); | |
$query->joinWith(['country']); | |
$dataProvider = new ActiveDataProvider([ | |
'query' => $query, | |
]); | |
$this->load($params); | |
if (!$this->validate()) { | |
return $dataProvider; | |
} | |
$query->andFilterWhere([ | |
'id' => $this->id, | |
'flat_rate' => $this->flat_rate, | |
'country.data' => $this->country_id, | |
'position' => $this->position, | |
'active' => $this->active, | |
]); | |
$dataProvider->sort->attributes['country'] = [ | |
'asc' => ['country.data' => SORT_ASC], | |
'desc' => ['country.data' => SORT_DESC], | |
]; | |
$query->andFilterWhere(['like', 'service_name', $this->service_name]); | |
return $dataProvider; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment