Example #1
0
 /**
  * Updates an existing User model.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = new UserForm();
     $model->setModel($this->findModel($id));
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     }
     return $this->render('update', ['model' => $model, 'roles' => User::getCustomRoles(), 'domains' => $this->_getDomainsArray()]);
 }
 /**
  * Updates an existing User model.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = new UserForm();
     $model->setModel($this->findModel($id));
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     }
     return $this->render('update', ['model' => $model, 'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')]);
 }
Example #3
0
 /**
  * Deletes an existing User model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = new UserForm();
     $session = Yii::$app->session;
     if ($model->deleteUser($id)) {
         $session->setFlash('info', Yii::t('back', 'User successfully deleted!'));
     } else {
         $session->setFlash('info', Yii::t('back', 'Something went wrong  - user not deleted!'));
     }
     return $this->redirect(['index']);
 }
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'index' page.
  *
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $user = new UserForm();
     $user->setModel($this->findModel($id));
     $profile = UserProfile::findOne($id);
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         $isValid = $user->validate();
         $isValid = $profile->validate() && $isValid;
         if ($isValid) {
             $user->save(false);
             $profile->save(false);
             return $this->redirect(['index']);
         }
     }
     return $this->render('update', ['user' => $user, 'profile' => $profile, 'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')]);
 }
 public function actionEdituser()
 {
     $req = Yii::$app->request;
     //创建一个请求对象
     $form = new UserForm();
     $form->setScenario('update');
     $id = trim($req->get('id'));
     if (!is_numeric($id) || $id == 0) {
         $this->redirect(Variable::$userMange_url);
         return;
     }
     //修改
     if ($form->load($req->post()) && $form->validate()) {
         $isSuccess = (new User())->updateCusetomer($id, $form->realName, $form->nickName, $form->password, $form->email, $form->mobile, $form->userType, $form->userStatus, $form->frozenReason, $form->comeFrom);
         if ($isSuccess) {
             $form->addError('', '资料更新成功');
         } else {
             $form->addError('', '资料更新失败');
         }
     }
     $userModel = User::findOne($id);
     $form->realName = $userModel->realName;
     $form->nickName = $userModel->nickName;
     $form->password = $userModel->password;
     $form->email = $userModel->email;
     $form->mobile = $userModel->mobile;
     $form->userType = $userModel->userType;
     $form->userStatus = $userModel->userStatus;
     $form->frozenReason = $userModel->frozenReason;
     $form->comeFrom = $userModel->comeFrom;
     return $this->render(Variable::$editUser_view, ['model' => $form, 'userModel' => $userModel]);
 }
 /**
  * Updates an existing User model.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     //         var_dump(ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name'));die();
     $model = new UserForm();
     $model->setModel($this->findModel($id));
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     }
     $roles = ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name');
     foreach ($roles as $key => $item) {
         if ($item == 'administrator') {
             unset($roles[$key]);
         }
         if ($item == 'manager') {
             $roles[$key] = '成为vip';
         }
         if ($item == 'user') {
             $roles[$key] = '普通用户';
         }
     }
     return $this->render('update', ['model' => $model, 'roles' => $roles]);
 }
Example #7
0
 public function actionEdit()
 {
     $request = Yii::$app->request;
     $user = User::findOne($request->get('id'));
     $model = new UserForm();
     $model->attributes = $user->attributes;
     if ($model->load($request->post()) && $model->validate()) {
         //Overall assignment the attributes of $user must be safe attributes
         $user->attributes = $model->attributes;
         // var_dump($model->attributes);
         // var_dump($user->attributes);exit();
         if ($user->save()) {
             $this->redirect(array('index'));
         } else {
         }
     } else {
         if ($model->hasErrors()) {
             // foreach($model->getErrors() as $error){
             // 	var_dump($error,false);
             // }
         }
     }
     return $this->render('edit', ['model' => $model]);
 }
Example #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserForm::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'username' => $this->username, 'email' => $this->email, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }