service = $service; } public function behaviors(): array { return [ 'access' => [ 'class' => AccessControl::className(), 'only' => ['index'], 'rules' => [ [ 'actions' => ['edit', 'social'], 'allow' => true, 'roles' => ['@'], ], ], ], ]; } /** * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionEdit() { $user = $this->findModel(Yii::$app->user->id); $form = new ProfileEditForm($user); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { $this->service->edit($user->id, $form); Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.')); return $this->redirect(['/account/profile/edit']); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } } return $this->render('edit', [ 'model' => $form, 'user' => $user, ]); } public function actionSocial() { return $this->render('social'); } /** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }