Yii2 调试面板仅在出现错误时显示

Yii2 debug panels are only showing when there's an error

我正在使用 Yii2 的 debug profiler 并且一切似乎都设置正确(我处于调试模式,我的 ip 被允许等)但是调试栏仅在出现 Yii 异常时显示,例如,如果我尝试访问 Yii::$app->paramssssss['test'],它将显示调试页面和调试栏。在任何其他页面上,它都不会显示。

有人遇到过类似的事情吗? This guy had the same issue 但这是一个 Vagrant 问题,我没有使用 Vagrant。

以下是我的部分配置:

...
'bootstrap' => ['debug'],
...
if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'panels' => [
            'db' => [
                'class' => 'yii\debug\panels\DbPanel',
                'defaultOrder' => [
                    'seq' => SORT_ASC
                ],
                'defaultFilter' => [
                    'type' => 'SELECT'
                ]
            ],
            'user' => [
                'class'=>'yii\debug\panels\UserPanel',
                'ruleUserSwitch' => [
                    'allow' => true,
                    'roles' => ['manager'],
                ]
            ],
        ],
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1', '*'],
    ];
}
...

可能您没有在布局中触发所需的事件。确保布局文件末尾有类似这样的内容:

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

您还应该阅读 this guide article 并确保您的布局中包含所有必需的触发器 - 省略它们会导致许多难以调试的错误。