public function beforeAction($action)
{
if (!$this->enableDebugLogs) {
foreach (Yii::$app->getLog()->targets as $target) {
$target->enabled = false;
}
}
if (!parent::beforeAction($action)) {
return false;
}
// do not display debug toolbar when in debug view mode
Yii::$app->getView()->off(View::EVENT_END_BODY, [$this, 'renderToolbar']);
Yii::$app->getResponse()->off(Response::EVENT_AFTER_PREPARE, [$this, 'setDebugHeaders']);
if ($this->checkAccess()) {
$this->resetGlobalSettings();
return true;
} elseif ($action->id === 'toolbar') {
// Accessing toolbar remotely is normal. Do not throw exception.
return false;
} else {
throw new ForbiddenHttpException('You are not allowed to access this page.');
}
}