diff --git a/backend/config/main.php b/backend/config/main.php index 8518676..1995c18 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -15,7 +15,6 @@ 'controllerNamespace' => 'backend\controllers', 'bootstrap' => [ 'log' ], 'controllerMap' => [ - 'settings' => 'artbox\core\controllers\SettingsController', 'profile' => 'artbox\core\controllers\ProfileController', 'page' => 'artbox\core\controllers\PageController', 'seo' => 'artbox\core\controllers\AliasController', diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php new file mode 100755 index 0000000..b0a0f9c --- /dev/null +++ b/backend/controllers/SettingsController.php @@ -0,0 +1,86 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'actions' => [ + 'logout', + 'index', + ], + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + + /** + * Display site settings page + * + * @return string|\yii\web\Response + */ + 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, + ] + ); + } + + /** + * Find site settings + * + * @return \yii2tech\filedb\ActiveRecord + * @throws \yii\base\InvalidConfigException + */ + public function findSettings() + { + if ($model = Settings::find() + ->one() + ) { + return $model; + } else { + throw new InvalidConfigException('Settings file not found'); + } + } + } + \ No newline at end of file diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index 7b274cb..413dba4 100755 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -70,19 +70,23 @@ public function actionIndex() { $settings = Settings::getInstance(); + + if (empty($settings->analytics_key)) { + return $this->render('index'); + } else { + $analytics = new Analytics( + [ + 'viewId' => $settings->analytics_key, + ] + ); - $analytics = new Analytics( - [ - 'viewId' => $settings->analytics_key, - ] - ); - - return $this->render( - 'analytics', - [ - 'data' => $analytics->generateData(), - ] - ); + return $this->render( + 'analytics', + [ + 'data' => $analytics->generateData(), + ] + ); + } } /** diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php index 99b3a61..115796f 100755 --- a/backend/views/settings/settings.php +++ b/backend/views/settings/settings.php @@ -35,13 +35,9 @@ echo $form->field($model, 'description') ->textInput(); - - echo $form->field($model, 'analytics') - ->textarea( - [ - 'rows' => 11, - ] - ); + + echo $form->field($model, 'analytics_key') + ->textInput(); echo Html::submitButton( 'Save', diff --git a/backend/views/site/analytics.php b/backend/views/site/analytics.php index f1d64e1..4836968 100644 --- a/backend/views/site/analytics.php +++ b/backend/views/site/analytics.php @@ -58,7 +58,7 @@ 'Analytics', - 'toolbarLayout' => '{collapse}', + 'toolbarLayout' => false, ] ); ?> @@ -124,7 +124,7 @@ 'Analytics', - 'toolbarLayout' => '{collapse}', + 'toolbarLayout' => false, ] ); ?> diff --git a/backend/views/site/index.php b/backend/views/site/index.php index 6719567..d1a56a8 100755 --- a/backend/views/site/index.php +++ b/backend/views/site/index.php @@ -1,9 +1,34 @@ title = 'My Yii Application'; - - \ No newline at end of file + $this->title = 'Artbox !'; + +?> + + 'Hello!', + 'toolbar' => false, + ] +); ?> + +
+ Configuration info + +