backend\models\OrderSearch::search PHP Метод

    public function search($params)
    {
        $query = Order::find();
        $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]);
        // load the seach form data and validate
        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }
        $this->_addDigitalFilter($query, 'real_fee');
        $dateBegin = strtotime($this->date);
        $dateEnd = $dateBegin + 86400;
        // adjust the query by adding the filters
        $query->andFilterWhere(['like', 'order_sn', $this->order_sn])->andFilterWhere(['school_id' => $this->school_id])->andFilterWhere(['store_id' => $this->store_id])->andFilterWhere(['user_id' => $this->user_id])->andFilterWhere(['payment' => $this->payment])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
        return $dataProvider;
    }

Usage Example

Пример #1
0
 /**
  * Lists all Order models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new OrderSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }