public function actionRegistration($role = '') { if (!\Yii::$app->user->isGuest) { $this->redirect(\Yii::$app->user->getReturnUrl()); } if ($role == '') { return $this->render('registration'); } $model = new User(); $role_model = new Company(); $model->role = User::ROLE_COMPANY; if ($role != 'company') { //Student registration $role = 'student'; $role_model = new Student(); $model->role = User::ROLE_STUDENT; } if ($model->load(Yii::$app->request->post()) && $role_model->load(Yii::$app->request->post()) && $model->register()) { if ($role == 'student') { $role_model->idUser = $model->id; if ($role_model->save()) { return $this->render('registration_student_success', ['model' => $model]); } } else { $role_model->idUser = $model->id; //Upload logo if (isset($_FILES['Company']) && $_FILES['Company']['name']['logo_path'] != "") { if (!in_array($_FILES['Company']['type']['logo_path'], $this->image_array)) { $role_model->addError('logo_path', 'Доступные расширения для файла: jpg, gif, png.'); } else { $rnd = rand(0, 9999); $uploadedFile = UploadedFile::getInstance($role_model, 'logo_path'); $fileName = 'files/' . $rnd . '_' . $uploadedFile->name; $role_model->logo_path = $fileName; $uploadedFile->saveAs($fileName); } } if ($role_model->save()) { return $this->render('registration_company_success', ['model' => $model]); } } } return $this->render('registration_' . $role, ['model' => $model, 'role_model' => $role_model]); }