/** * Creates a new ResumeProfession model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ResumeProfession(); 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]); } }
/** * @param bool $insert * @param array $changedAttributes * * Сохранение должностей */ public function afterSave($insert, $changedAttributes) { if (!$insert) { ResumeProfession::deleteAll(['resume_id' => $this->id]); } if (is_array($this->professions)) { foreach ($this->professions as $prof) { $profLink = new ResumeProfession(); $profLink->resume_id = $this->id; $profLink->profession_id = $prof; $profLink->save(); } } }