/** * Creates a new Block model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Block(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'slug' => $model->slug]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Block(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', '{model} SUCCESS_CREATED', ['model' => $model->title])); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Block model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Block(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (isset($_POST['title']) && is_array($_POST['title'])) { foreach ($_POST['title'] as $lang => $val) { $model->setTitle($lang, $val); } } if (isset($_POST['content']) && is_array($_POST['content'])) { foreach ($_POST['content'] as $lang => $val) { $model->setContent($lang, $val); } } $model->updateURLCode(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionSetupBlock($sectionId, $blockPath) { $query = new QueryBuilder(); $query->select('MAX(' . Block::getDbDriver()->quoteName('order') . ')')->from(Block::getTableName())->where('section=:section')->params([':section' => $sectionId]); $maxOrder = (int) $this->app->db->default->query($query)->fetchScalar(); $block = new Block(); $block->section = $sectionId; $block->path = $blockPath; $block->template = ''; $params = []; foreach ($this->app->config->blocks->{$blockPath}->options as $optionName => $options) { $params[$optionName] = $options->default; } $block->options = json_encode($params); $block->order = $maxOrder + 10; if (false !== $block->save()) { $this->data->id = $block->getPK(); $this->data->result = true; } else { $this->data->result = false; } }