jahau
(Jahau)
1
How to add more than one condition to the following dataprovider, e.g. ORDER_STATUS_UNDER_WORK?
$dataProvider = $searchModel->search(\yii\helpers\ArrayHelper::merge(
Yii::$app->request->queryParams,
[$searchModel->formName() => ['status' => ORDER_STATUS_CREATED]]
));
I usually split "search" model into two method: "searchQuery" and "search", in this way:
public function searchQuery($params)
{
$query = Model::find();
$this->load($params);
// grid filtering conditions
$query->andFilterWhere([
// ...
]);
return $dataProvider;
}
public function search($query)
{
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $dataProvider;
}
So you can use in actionIndex:
$query = $searchModel->searchQuery(Yii::$app->request->queryParams);
$query->andWhere(['status' => ORDER_STATUS_CREATED);
$dataProvider = $searchModel->search($query);