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.
  * 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')]);
 }
Exemple #3
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]);
 }