/**
  * Creates a new CsObjects model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new CsObjects();
     $model_trans = new CsObjectsTranslation();
     if ($objects = Yii::$app->request->get('CsObjects')) {
         $model->object_id = !empty($objects['object_id']) ? $objects['object_id'] : null;
         $model->object_type_id = !empty($objects['object_type_id']) ? $objects['object_type_id'] : null;
     }
     if ($model->load(Yii::$app->request->post()) and $model_trans->load(Yii::$app->request->post())) {
         $parent = $this->findModel($model->object_id);
         $model->level = $parent->level + 1;
         if ($model->save()) {
             if ($model->imageFile) {
                 $model->upload();
             }
             $model_trans->object_id = $model->id;
             $model_trans->orig_name = $model->name;
             $model_trans->save();
             //if($model_trans->save()){
             return $this->redirect(['view', 'id' => $model->id]);
             //}
         }
     } else {
         return $this->render('create', ['model' => $model, 'model_trans' => $model_trans]);
     }
 }
 /**
  * Finds the CsServicesTranslation model based on its translated title.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CsServices the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelByTitle($title)
 {
     if (($model = \common\models\CsObjectsTranslation::find()->where('name=:name and lang_code="SR"', [':name' => str_replace('-', ' ', $title)])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslation()
 {
     $object_translation = CsObjectsTranslation::find()->where('lang_code="SR" and object_id=' . $this->id)->one();
     if ($object_translation) {
         return $object_translation;
     }
     return false;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObjectsTranslations()
 {
     return $this->hasMany(CsObjectsTranslation::className(), ['lang_code' => 'code']);
 }