/** * Finds the DctVaccinationLoc model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DctVaccinationLoc the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DctVaccinationLoc::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing DctVaccination model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $languages = $this->getLanguages(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $params = Yii::$app->request->post(); DctVaccinationLoc::saveLocalizationData($model, $params, count($languages)); return $this->redirect(['view', 'id' => $model->dct_vaccination_id]); } else { return $this->render('update', ['model' => $model, 'languages' => $languages, 'modelLoc' => DctVaccinationLoc::getLocalizationData($id)]); } }
public function saveLocalizationData($model, $params, $languageCount) { for ($i = 0; $i < $languageCount; $i++) { if ($model->dct_vaccination_id > -1) { $childModel = new DctVaccinationLoc(); $childModel->dct_vaccination_id = $model->dct_vaccination_id; $childModel->dct_language_id = $params[$i]['dct_language_id']; } else { $childModel = DctVaccinationLoc::findOne($params[$i]['dct_vaccination_loc_id']); } $childModel->text = !empty($params[$i]['text']) ? $params[$i]['text'] : ''; $childModel->genitive_text = !empty($params[$i]['genitive_text']) ? $params[$i]['genitive_text'] : ''; $childModel->save(); } }
/** * @return \yii\db\ActiveQuery */ public function getDctVaccinationLocs() { return $this->hasMany(DctVaccinationLoc::className(), ['dct_vaccination_id' => 'dct_vaccination_id']); }