/** * Shows user's profile. * @param integer $id * @return \yii\web\Response * @throws \yii\web\NotFoundHttpException */ public function actionShow($id) { $profile = $this->finder->findProfileById($id); if ($profile === null) { throw new NotFoundHttpException(); } return $this->render('show', ['profile' => $profile]); }
/** * Displays page where user can update account settings (username, email or password). * @return string|\yii\web\Response */ public function actionAccount() { $profileModel = $this->finder->findProfileById(\Yii::$app->user->identity->getId()); $accountModel = \Yii::createObject(SettingsForm::className()); $this->performAjaxValidation($profileModel); $this->performAjaxValidation($accountModel); if ($profileModel->load(\Yii::$app->request->post()) && $accountModel->load(\Yii::$app->request->post())) { if ($profileModel->validate() && $accountModel->validate() && $profileModel->save() && $accountModel->save()) { Event::trigger(BaseController::class, BaseController::EVENT_MODEL_UPDATED, new MessageEvent($profileModel)); \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'Your account has been updated')); return $this->refresh(); } } return $this->render('account', ['profileModel' => $profileModel, 'accountModel' => $accountModel]); }
/** * 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 = $this->findModel($id); $user->scenario = 'update'; $profile = $this->finder->findProfileById($id); $r = \Yii::$app->request; $this->performAjaxValidation([$user, $profile]); if ($user->load($r->post()) && $profile->load($r->post()) && $user->save() && $profile->save()) { Event::trigger(BaseController::class, BaseController::EVENT_MODEL_UPDATED, new MessageEvent($profile)); $this->trigger(BaseController::EVENT_MODEL_UPDATED, new MessageEvent($user)); \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been updated')); return $this->redirect(['index']); } return $this->render('update', ['user' => $user, 'profile' => $profile, 'module' => $this->module]); }