A
A
akula222017-06-10 15:45:54
Yii
akula22, 2017-06-10 15:45:54

How to competently close the site by option?

If Yii::$app->params['is_offline'] == 1 I need to close the site, but access to the admin panel should remain. The admin panel is made simply by a module, on the same domain. Tell me how best to do this?
In which file should the check be done, not in the index.php?
and how to make a check so that access to the admin panel remains

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akula22, 2017-06-10
@akula22

While waiting for an answer, I myself came up with such a solution, please check it out.
in config

'bootstrap' => [
        'app\components\MainComponent',
    ],

and MainComponent itself
class MainComponent extends Component
{
    public $roles = ['root', 'admin']; // разрешенные роли

    public function init()
    {
        if (Yii::$app->params['is_offline'] == 1) {
            $enable_role = in_array(Yii::$app->user->identity->role, $this->roles);

            $ips = explode(',', Yii::$app->params['allow_ip']);
            $ips = array_map("trim", $ips);
            $enable_ip = in_array($this->getIp(), $ips); //check "allowed IP"

            if(!$enable_role AND !$enable_ip) {
                die(Yii::$app->params['closeText']);
            }
        }
    }

M
Maxim Timofeev, 2017-06-11
@webinar

not in index.php?

Why not?
Just connect different configs in index php depending on the need. In yii2, there is initially a similar feature for dev and prod. Add the close option, while connecting the admin module in the config and do not connect others or anything else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question