コード例 #1
0
 public function actionProfile()
 {
     // Устанавливаем сценарий валидации
     $form = new ProfileForm();
     $form->setScenario('profile');
     // Загружаем в форму данные пользователя
     $User = Yii::$app->user->getIdentity();
     $form->setUser($User);
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         // Сохраняем пользователя с данными из формы
         if ($form->save($User)) {
             Yii::$app->session->setFlash('success', 'Данные успешно сохранены.');
         } else {
             Yii::$app->session->setFlash('error', 'Произошла ошибка при сохранении данных пользователя.');
         }
         return $this->refresh();
     }
     $orders = Order::findAll(['user_id' => $User->id]);
     $template = Yii::$app->request->get('edit') ? 'profile_edit' : 'profile';
     $form->birthday_date = date('d.m.Y', strtotime($form->birthday_date));
     return $this->render($template, ['model' => $form, 'orders' => $orders]);
 }
コード例 #2
0
ファイル: UserController.php プロジェクト: shapik2004/album2
 public function actionProfile()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute(['intro/index']));
         return;
     }
     if (Yii::$app->user->identity->role == User::ROLE_DEMO) {
         $this->redirect(Url::toRoute(['user/signup-demo']));
         return;
     }
     $this->layout = 'default';
     $model = new ProfileForm();
     if ($model->load(Yii::$app->request->post(), 'ProfileForm')) {
         if ($model->validate()) {
             if ($model->save()) {
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Изменения успешно сохранены.'));
                 return $this->redirect(Url::toRoute('user/profile'));
             } else {
             }
         } else {
         }
     } else {
         if (!$model->loadByUserId(Yii::$app->user->identity->getId())) {
         }
     }
     $settings = new SettingForm();
     $currencies = $settings->getValue('currencies', []);
     $currencies_new = [];
     foreach ($currencies as $key => $currency) {
         $currencies_new[$currency['code']] = $currency['code'];
     }
     return $this->render('profile', ['model' => $model, 'currencies' => $currencies_new]);
 }