Exemple #1
0
 public function actionRegistration()
 {
     $userRegistrationForm = new UserRegistrationForm();
     if (Yii::$app->request->isPost) {
         $userRegistrationForm->load(Yii::$app->request->post());
         $userRegistrationForm->avatar = UploadedFile::getInstance($userRegistrationForm, 'avatar');
         try {
             if ($user = $userRegistrationForm->registrate()) {
                 Yii::$app->user->login($user);
                 $this->goHome();
             }
         } catch (yii\base\Exception $e) {
             $userRegistrationForm->addError('form', 'Ошибка регистрации');
         }
     }
     return $this->render('/registration', ['model' => $userRegistrationForm]);
 }
 public function actionIndex()
 {
     $usermodel = new UserRegistrationForm();
     $artmodel = new ArtisanRegistrationForm();
     $usform = Yii::$app->request->post('UserRegistrationForm');
     $artform = Yii::$app->request->post('ArtisanRegistrationForm');
     if ($usform) {
         $model->attributes = $usform;
         if ($model->validate()) {
             Users::adduser($model);
             $model = new UserRegistrationForm();
             return $this->render('index', ['usermodel' => $model, 'artmodel' => $artmodel]);
         }
     } elseif ($artform) {
         $model->attributes = $artform;
         if ($model->validate()) {
             Users::adduser($model);
             $model = new ArtisanRegistrationForm();
             return $this->render('index', ['usermodel' => $usermodel, 'artmodel' => $model]);
         }
     } else {
         return $this->render('index', ['usermodel' => $usermodel, 'artmodel' => $artmodel]);
     }
 }