Exemplo n.º 1
0
 public function actionUpdateProfile()
 {
     $model = UserProfile::findOne(Yii::$app->user->id);
     $model = $model ?: new UserProfile(['id' => Yii::$app->user->id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['profile']);
     }
     return $this->render('update-profile', ['model' => $model]);
 }
Exemplo n.º 2
0
 public function actionUpdateProfile()
 {
     $model = UserProfile::findOne(Yii::$app->user->id);
     $model = $model ?: new UserProfile(['id' => Yii::$app->user->id]);
     if ($model->load(Yii::$app->request->post())) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             if ($model->save()) {
                 $transaction->commit();
                 return $this->redirect(['profile']);
             }
         } catch (\Exception $exc) {
             $model->addError('', $exc->getMessage());
         }
         $transaction->rollBack();
     }
     return $this->render('update-profile', ['model' => $model]);
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProfile()
 {
     return $this->hasOne(UserProfile::className(), ['id' => 'id']);
 }