/**
  * Finds the DctSolidFoodLoc model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DctSolidFoodLoc the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DctSolidFoodLoc::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Updates an existing DctSolidFood 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();
         DctSolidFoodLoc::saveLocalizationData($model, $params, count($languages));
         return $this->redirect(['view', 'id' => $model->dct_solid_food_id]);
     } else {
         return $this->render('update', ['model' => $model, 'languages' => $languages, 'modelLoc' => DctSolidFoodLoc::getLocalizationData($id)]);
     }
 }
Exemplo n.º 3
0
 public function saveLocalizationData($model, $params, $languageCount)
 {
     for ($i = 0; $i < $languageCount; $i++) {
         if ($model->dct_solid_food_id > -1) {
             $childModel = new DctSolidFoodLoc();
             $childModel->dct_solid_food_id = $model->dct_solid_food_id;
             $childModel->dct_language_id = $params[$i]['dct_language_id'];
         } else {
             $childModel = DctSolidFoodLoc::findOne($params[$i]['dct_solid_food_loc_id']);
         }
         $childModel->text = !empty($params[$i]['text']) ? $params[$i]['text'] : '';
         $childModel->save();
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDctSolidFoodLocs()
 {
     return $this->hasMany(DctSolidFoodLoc::className(), ['dct_solid_food_id' => 'dct_solid_food_id']);
 }