backend\models\AdminSearch::search PHP Method

    public function search($params)
    {
        $query = Admin::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;
        }
        $dateBegin = strtotime($this->date);
        $dateEnd = $dateBegin + 86400;
        // adjust the query by adding the filters
        $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'real_name', $this->real_name])->andFilterWhere(['gender' => $this->gender])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
        return $dataProvider;
    }

Usage Example

Beispiel #1
0
 /**
  * Lists all Admin models.
  * @return mixed
  */
 public function actionIndex()
 {
     //if(!Yii::$app->user->can('viewUser')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $searchModel = new AdminSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $arrayStatus = Admin::getArrayStatus();
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'arrayStatus' => $arrayStatus]);
 }
All Usage Examples Of backend\models\AdminSearch::search
AdminSearch