/** * @return string|\yii\web\Response */ public function actionChangeProfile() { // $accountModel = new AccountForm(); // $accountModel->setUser(Yii::$app->user->identity); // $model = new MultiModel([ // 'models' => [ // 'account' => $accountModel, // 'profile' => Yii::$app->user->identity->userProfile // ] // ]); // if ($model->load(Yii::$app->request->post()) && $model->save()) { // Yii::$app->session->setFlash('alert', [ // 'options' => ['class'=>'alert-success'], // 'body' => Yii::t('frontend', 'Your account has been successfully saved') // ]); // return $this->refresh(); // } // return $this->render('change', ['model'=>$model]); $model = new UserForm(); $model->setModel($this->findModel(\Yii::$app->user->id)); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } return $this->render('change', ['model' => $model]); }
/** * 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')]); }
/** * 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. * 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')]); }
/** * 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]); }