/** * @inheritdoc */ public function getModel($id = 0) { $model = parent::getModel($id); if (!$id || !isset($model->params['images'])) { $params = is_array($model->params) ? $model->params : []; $params['images'] = ['images' => [], 'config' => Gallery::getDefaultOptions()]; $model->params = $params; } return $model; }
/** * Creates and edits a page. * * @param int optional id of a page to edit. If id is not provided * a new page is created. * @return string */ public function actionEdit($id = 0) { $model = new Page(); if ($id) { $model = Page::find()->where(['id' => $id])->with(['author', 'editor'])->one(); } else { $model->images['config'] = Gallery::getDefaultOptions(); } $request = Yii::$app->getRequest(); if ($model->load($request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('cms', 'Page saved')); if (Yii::$app->toolbar->stayAfterSave()) { return $this->redirect(['edit', 'id' => $model->id]); } else { return $this->redirect(['index']); } } $categories = Yii::$app->big->categoryManager->getDropDownList('pages'); $templates = Yii::$app->big->templateManager->getDropDownList(Yii::t('cms', '- Use default template -')); return $this->render('edit', ['model' => $model, 'templates' => $templates, 'categories' => $categories]); }