コード例 #1
0
ファイル: UserSearch.php プロジェクト: kuzmiand/yii2-users
 public function search($params)
 {
     $query = User::find();
     $query->with(['roles']);
     if (!Yii::$app->user->identity->isSuperadmin) {
         $query->where(['superadmin' => 0]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->gridRoleSearch) {
         $query->joinWith(['roles']);
     }
     $query->andFilterWhere(['id' => $this->id, 'superadmin' => $this->superadmin, 'status' => $this->status, Yii::$app->getModule('user')->auth_item_table . '.name' => $this->gridRoleSearch, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Lists all User models.
  * @return mixed
  */
 public function actionIndexOld()
 {
     $dataProvider = new ActiveDataProvider(['query' => User::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }