public function run() { $request = Yii::$app->request; $ident = Yii::$app->user->getIdentity(); $form = new ProfileForm(); if ($request->isPost) { $form->load($request->bodyParams); if ($form->validate()) { $transaction = Yii::$app->db->beginTransaction(); try { $ident->attributes = $form->attributes; $ident->env_id = $this->findOrCreateEnvironmentId($form->env); $ident->is_black_out_others = $form->is_black_out_others == '1'; if ($ident->save()) { $transaction->commit(); $this->controller->redirect(['user/profile']); return; } } catch (\Exception $e) { } $transaction->rollback(); } } else { $form->attributes = $ident->attributes; if ($ident->env) { $form->env = $ident->env->text; } $form->is_black_out_others = $ident->is_black_out_others ? '1' : '0'; } return $this->controller->render('edit-profile.tpl', ['user' => $ident, 'form' => $form]); }
public function actionProfile() { if (!is_null($user = $this->getLoggedUser())) { $profile = new ProfileForm($user); if (Yii::$app->request->isPost && $profile->load(Yii::$app->request->post()) && $profile->validate() && $profile->update($user)) { } return $this->render('profile', ['model' => $profile, 'user' => $user]); } else { return $this->redirect(['site/register']); } }
public function run() { $request = Yii::$app->request; $ident = Yii::$app->user->getIdentity(); $form = new ProfileForm(); if ($request->isPost) { $form->load($request->bodyParams); if ($form->validate()) { $ident->attributes = $form->attributes; if ($ident->save()) { $this->controller->redirect(['user/profile']); return; } } } else { $form->attributes = $ident->attributes; } return $this->controller->render('edit-profile.tpl', ['user' => $ident, 'form' => $form]); }