/** * Updates an existing profile. * * @param int $id * * @return mixed */ public function actionUpdateProfile($id) { Url::remember('', 'actions-redirect'); $user = $this->findModel($id); $profile = $user->profile; if ($profile == null) { $profile = Yii::createObject(Profile::className()); $profile->link('user', $user); } $this->performAjaxValidation($profile); if ($profile->load(Yii::$app->request->post()) && $profile->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile details have been updated')); return $this->refresh(); } return $this->render('_profile', ['user' => $user, 'profile' => $profile]); }
/** @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($insert) { $profile = \Yii::createObject(['class' => Profile::className(), 'user_id' => $this->id, 'gravatar_email' => $this->email]); $profile->save(false); } parent::afterSave($insert, $changedAttributes); }