From 2f3cd090b8f8e93712f140fcbab5d7082b4e690c Mon Sep 17 00:00:00 2001 From: yarik Date: Tue, 21 Mar 2017 18:24:18 +0200 Subject: [PATCH] Setting migrate --- backend/controllers/SettingsController.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/settings/settings.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/Settings.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+), 0 deletions(-) create mode 100755 backend/controllers/SettingsController.php create mode 100755 backend/views/settings/settings.php create mode 100755 common/models/Settings.php diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php new file mode 100755 index 0000000..f9885f1 --- /dev/null +++ b/backend/controllers/SettingsController.php @@ -0,0 +1,79 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'actions' => [ + 'logout', + 'index', + ], + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + /** + * @return bool|string + */ + public function getViewPath() + { + return \Yii::getAlias('@artbox/core/views/settings'); + } + + public function actionIndex() + { + $model = $this->findSettings(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + Yii::$app->session->setFlash('success', 'Settings saved'); + + return $this->goHome(); + } + + return $this->render( + 'settings', + [ + 'model' => $model, + ] + ); + } + + public function findSettings() + { + if ($model = Settings::find() + ->one() + ) { + return $model; + } else { + throw new ConfigurationException('Settings file not found'); + } + } + } \ No newline at end of file diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php new file mode 100755 index 0000000..99b3a61 --- /dev/null +++ b/backend/views/settings/settings.php @@ -0,0 +1,57 @@ +title = 'Settings'; + + $this->params[ 'breadcrumbs' ][] = $this->title; +?> + + $this->title, + 'toolbar' => false, + ] +); ?> + +
+ + field($model, 'id') + ->textInput(); + + echo $form->field($model, 'name') + ->textInput(); + + echo $form->field($model, 'description') + ->textInput(); + + echo $form->field($model, 'analytics') + ->textarea( + [ + 'rows' => 11, + ] + ); + + echo Html::submitButton( + 'Save', + [ + 'class' => 'btn btn-primary', + ] + ); + ActiveForm::end(); + ?> + +
+ + diff --git a/common/models/Settings.php b/common/models/Settings.php new file mode 100755 index 0000000..ae2b93d --- /dev/null +++ b/common/models/Settings.php @@ -0,0 +1,67 @@ + Yii::t('core', 'ID'), + 'name' => Yii::t('core', 'Name'), + 'description' => Yii::t('core', 'Description'), + 'analytics' => Yii::t('core', 'Google Analytics Code'), + ]; + } + + /** + * Get Settings model instance + * + * @return Settings + */ + public static function getInstance() + { + return self::findOne([ 'id' => 1 ]); + } + } + \ No newline at end of file -- libgit2 0.21.4