/** * Creates a new Block model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($source_id = -1, $lang_id = -1) { if ($lang_id == -1) { $lang_id = Language::getDefaultID(); } $model = new Block(); $model->source_id = $source_id; $model->lang_id = $lang_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new item * @return mixed */ public function actionCreateItem($menu_id, $source_id = -1, $lang_id = -1) { if ($lang_id == -1) { $lang_id = Language::getDefaultID(); } $menu = $this->findModel($menu_id); $items = $menu->items; $model = new MenuItem(); $model->menu_id = $menu_id; $model->source_id = $source_id; $model->lang_id = $lang_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['items', 'id' => $menu->id]); } else { return $this->render('create_item', ['items' => $items, 'menu' => $menu, 'model' => $model]); } }
/** * Finds source node * @return $this|array|null|\yii\db\ActiveRecord */ public function getSource() { if ($this->source_id == -1) { return $this; } return $this->find()->where(['id' => $this->getSourceID(), 'lang_id' => Language::getDefaultID()])->one(); }