/** * Creates a new CsCategories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CsCategories(); $model_trans = new CsCategoriesTranslation(); if ($model->load(Yii::$app->request->post()) and $model_trans->load(Yii::$app->request->post())) { if ($model->save()) { $model_trans->category_id = $model->id; $model_trans->orig_name = $model->name; $model_trans->save(); return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'model_trans' => $model_trans]); } }
/** * @return \yii\db\ActiveQuery */ public function getTranslation() { $category_translation = \common\models\CsCategoriesTranslation::find()->where('lang_code="SR" and category_id=' . $this->id)->one(); if ($category_translation) { return $category_translation; } return false; }
/** * @return \yii\db\ActiveQuery */ public function getT() { return $this->hasMany(CsCategoriesTranslation::className(), ['category_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getCategoriesTranslations() { return $this->hasMany(CsCategoriesTranslation::className(), ['lang_code' => 'code']); }