/** * Creates a new Vacancy model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Vacancy(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Vacancy model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Vacancy(); //Подставляем значения по умолчанию $model->firm_id = \app\models\User::findOne(Yii::$app->user->id)->firm_id; $model->workplace_id = \app\models\User::findOne(Yii::$app->user->id)->workplace_id; $model->date = Yii::$app->getFormatter()->asDate(time()); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->addFlash('success', "Запись #{$model->id} успешно добавлена."); return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]); } else { if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) { Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null); } if (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } return $this->render('create', ['model' => $model]); } }
public function createnewstep3() { $model = new Vacancy(); $preferences = new Preferences(); $data = Yii::$app->request->post(); $model->load($data); $preferences->load($data); $transaction = \Yii::$app->db->beginTransaction(); try { //TODO check for errors and cancel transaction $model->save(); $model->savePreferences($preferences); $connection = \Yii::$app->db; // TODO Place this in preferences logic $connection->createCommand("INSERT INTO person_vacancy_role (person_id, vacancy_id, role_id) " . "VALUES (:person_id, :vacancy_id, :role_id)")->bindValues([":person_id" => \YII::$app->getUser()->getIdentity()->getId(), ":vacancy_id" => $model->getPrimaryKey(), ":role_id" => VacancyRoleHelper::OWNER])->execute(); // Vacanty - course_id $course_id = $this->getSession()['create-new-vacancy-course-id']; if (isset($course_id) && $course_id != "none") { $connection->createCommand("INSERT INTO course_vacancy (course_id, vacancy_id) VALUES (:course_id, :vacancy_id)")->bindValues([":course_id" => $course_id, ":vacancy_id" => $model->getPrimaryKey()])->execute(); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); throw $e; } return $this->actionView($model->id); }