V
V
Vladislav2020-04-13 13:27:36
Yii
Vladislav, 2020-04-13 13:27:36

How to make those work on the site on / off through catchAll?

Hello everyone, I have a question about the implementation on an already working site.
I know that there is in the config , How to make it possible to simply change one field in the database, for example, with the name site_offline 0 | 1 and if 1 then in the config it will be catchAll if 0 then it is not there and the site works. in normal mode. 'catchAll' => ['site/offline']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-04-13
@cr1gger

You can use as Dmitry suggested ,

'on afterAction'  => function ($event) {
      if ( Yii::$app->siteSettings->get('SITE.OFF_LINE') == 'on' ) {
        if ( !Yii::$app->user->isGuest && !Yii::$app->user->can('admin') ) {
          Yii::$app->user->logout();
          return Yii::$app->response->redirect([ 'offline/off-mode' ]);
        }
      }
      return false;
    },
but move this code into a behavior. It is better not to leave it in the config.
You can also use this module https://github.com/Dominus77/yii2-config-db, or create something of your own by analogy with this module.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question