Answer the question
In order to leave comments, you need to log in
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
While waiting for an answer, I myself came up with such a solution, please check it out.
in config
'bootstrap' => [
'app\components\MainComponent',
],
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']);
}
}
}
not in index.php?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question