/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query->where(['status' => [Admin::STATUS_ACTIVE, Admin::STATUS_INACTIVE]])]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'auth_role' => $this->auth_role, 'status' => $this->status, 'birthdate' => $this->birthdate]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'role' => $this->role, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'nicename', $this->nicename])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]); return $dataProvider; }
public function userAction() { if ($this->request->isPost()) { $this->view->disable(); $post = json_decode(file_get_contents("php://input"), true); $where = '1=1'; empty($post['username']) || ($where .= " and name like '%" . htmlspecialchars(trim($post['username'])) . "%'"); empty($post['depart']) || ($where .= " and depart=" . intval($post['depart'])); $limit = array('number' => $this->config->pageNum, 'offset' => (intval($post['p']) - 1) * $this->config->pageNum); $arr = array($where, 'limit' => $limit, 'order' => 'id desc'); $user = Admin::find($arr); $total = Admin::count($where); $info = array('total' => ceil($total / $this->config->pageNum), 'info' => $user->toArray()); echo json_encode($info); } $this->view->departs = Depart::find()->toArray(); }
public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { $user = Admin::find()->where(['username' => $_POST['LoginForm']['username']])->one(); //设置session $session = Yii::$app->session; $session['userid'] = $user->id; $session['username'] = $user->username; $session['head_image'] = $user->head_image; return $this->redirect(['/admin/index']); } else { return $this->renderPartial('login', ['model' => $model, 'assets_url' => \Yii::$app->params['backend_assets']]); } }
public function sayAction() { $this->view->disable(); $user = Admin::find(); var_dump($user->toArray()); }
/** * Lists all Admin models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Admin::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }