public function search() { $page = Yii::$app->request->get('page', 0); $page = $page < 0 ? 0 : $page - 1; $limit = Yii::$app->request->get('limit', 25); $sorts = json_decode(trim(Yii::$app->request->get('sort')), true); $startDay = Yii::$app->request->get('start_date'); $endDay = Yii::$app->request->get('end_date'); $locationId = Yii::$app->request->get('location_id'); $areaId = Yii::$app->request->get('area_id'); $query = MaggieBox::find()->filterWhere(['between', 'date', $startDay, $endDay])->andFilterWhere(['location_id' => $locationId, 'area_id' => $areaId]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $limit]); if ($sorts != null) { foreach ($sorts as $sort) { $query->addOrderBy([$sort['property'] => $sort['direction'] == 'ASC' ? SORT_ASC : SORT_DESC]); } } else { $query->addOrderBy(['id' => SORT_DESC]); } //var_dump($query);exit; $model = $query->offset($pagination->offset)->limit($limit)->all(); return ['count' => $countQuery->count(), 'model' => $model]; }