Beispiel #1
0
 /** @inheritdoc */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         if ($this->_profile == null) {
             $this->_profile = Yii::createObject(Profile::className());
         }
         $this->_profile->link('user', $this);
     }
 }
 /**
  * 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]);
 }