/** 查询 */ public function actionSearch() { $request = Yii::$app->request; $query = Yii::$app->session->getFlash('query'); if ($request->isPost) { $type = $request->post('type'); $content = trim($request->post('content')); } else { $type = $request->get('type'); $content = trim($request->get('content')); } if ($type || !$query) { $user = Yii::$app->session->get('user'); $query = Users::find()->where(['recommendUserID' => $user['userId']]); switch ($type) { case 'userId': $query = $query->andWhere(['userId' => $content]); break; case 'nickname': case 'realname': $query = $query->andWhere(['like', $type, $content]); break; default: break; } } Yii::$app->session->setFlash('query', $query); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $users = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['registerDate' => SORT_DESC])->all(); return $this->render('index', ['users' => $users, 'pages' => $pagination]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::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, 'dob' => $this->dob, 'is_active' => $this->is_active, 'is_deleted' => $this->is_deleted, 'app_status' => $this->app_status, 'otp' => $this->otp, 'created_date' => $this->created_date, 'created_by' => $this->created_by, 'updated_date' => $this->updated_date, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'gender', $this->gender])->andFilterWhere(['like', 'device_token', $this->device_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'role', $this->role])->andFilterWhere(['like', 'mood_message', $this->mood_message])->andFilterWhere(['like', 'area_intrest', $this->area_intrest])->andFilterWhere(['like', 'about_me', $this->about_me]); return $dataProvider; }
public function login() { $user = Users::find()->where(['username' => $this->username])->one(); if ($user) { if ($user['state'] == Users::STATE_STOP) { //用户状态被终止 $this->addError('username', "该用户已被终止登录"); return false; } if ($user['password'] != CommonFunctions::encrypt($this->password)) { $this->addError('password', "密码错误"); return false; } Yii::$app->session->set('user', $user); return true; } else { $this->addError('username', "用户不存在"); return false; } }
public function actionSearch() { $request = Yii::$app->request; $query = Yii::$app->session->getFlash('query'); if ($request->isPost) { $type = $request->post('type'); $content = trim($request->post('content')); } else { $type = $request->get('type'); $content = trim($request->get('content')); } if ($type || !$query) { switch ($type) { case 'province': $table_a = Users::tableName(); $table_b = Province::tableName(); $query = Users::find()->leftJoin($table_b, "{$table_a}.provinceId={$table_b}.provinceId")->where(['like', "{$table_b}.name", $content]); break; case 'majorJob': $table_a = Users::tableName(); $table_b = MajorJob::tableName(); $query = Users::find()->leftJoin($table_b, "{$table_a}.majorJobId={$table_b}.majorJobId")->where(['like', $table_b . ".name", $content]); break; case 'nickname': case 'cellphone': $query = Users::find()->where(['like', $type, $content]); break; default: $query = Users::find(); break; } $query = $query->andWhere('weixin is not null'); //添加微信用户条件,位置不可改 } Yii::$app->session->setFlash('query', $query); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $user = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['registerDate' => SORT_DESC])->all(); return $this->render('index', ['users' => $user, 'pages' => $pagination]); }
/** * 查询被推荐的人 * @param $userId * @return array|\yii\db\ActiveRecord[] */ public static function findBeRecommend($userId) { return Users::find()->where(['recommendUserID' => $userId])->all(); }
public function actionIndex() { $users = Users::find()->where(['>=', 'role', Users::ROLE_ADMIN])->all(); return $this->render('index', ['users' => $users]); }
<h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Checkin', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'users.username', 'filter' => \yii\helpers\ArrayHelper::map(\common\models\Users::find()->orderBy('username')->asArray()->all(), 'id', 'username')], 'event.title', ['attribute' => 'user_type', 'filter' => \yii\helpers\ArrayHelper::map(\common\models\Checkin::find()->orderBy('user_type')->asArray()->all(), 'id', 'user_type')], 'created_date', ['class' => 'yii\\grid\\ActionColumn']]]); ?> <?php // You only need add this, $this->registerJs(' var gridview_id = ""; // specific gridview var columns = [2]; // index column that will grouping, start 1 var column_data = []; column_start = []; rowspan = []; for (var i = 0; i < columns.length; i++) { column = columns[i]; column_data[column] = "";
/** * Lists all Users models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Users::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }