Example #1
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->saveUser($id)) {
         $session = Yii::$app->session;
         $session->setFlash('info', Yii::t('back', 'User successfully updated!'));
         return $this->redirect(['index']);
     } else {
         $user = $this->findModel($id);
         $model->username = $user->username;
         $model->email = $user->email;
         $model->password = '';
         $auth = Yii::$app->authManager;
         $roles = array_keys($auth->getRolesByUser($id));
         $model->role = count($roles) ? $roles[0] : '';
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', compact('model'));
     }
     return $this->render('_form', compact('model'));
 }