Skip to content

Instantly share code, notes, and snippets.

@c006
Created January 17, 2016 05:28
Show Gist options
  • Save c006/28a0f0f544a0bcaee6ca to your computer and use it in GitHub Desktop.
Save c006/28a0f0f544a0bcaee6ca to your computer and use it in GitHub Desktop.
Yii2 Model Search
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