I'm using Craft 3 RC and I am logged as an admin. How can I display the Yii debug toolbar on front-end and Control Panel requests? By default, I don't see this toolbar.
3 Answers
There are two checkboxes in your user settings, go to your admin account -> preferences index.php?p=admin/myaccount
and check the boxes
This is covered in detail in the Profiling your Website with Craft CMS 3’s Debug Toolbar article
-
1I did that as well but the front end console won't show up but the cp does.– Mark H.Mar 9, 2018 at 19:06
-
-
-
I don't really see an issue. You can have the debug toolbar for whatever site you want Nov 7, 2019 at 15:15
-
This may seem obvious but if you've enabled the debug toolbar for the front end and can't see it. Check your HTML for unclosed divs etc. This can prevent the debug toolbar from being shown on pages with broken HTML. Dec 5, 2019 at 14:53
Craft 3
If you enabled the debug toolbar in the user profile, but it still does not show on the frontend, AND you are running Craft not locally but on a different host (different IP), try adding this to your config/app.php:
'local' => [
'bootstrap' => ['debug'],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
// uncomment and adjust the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', '*.*.*.*'],
]
]
],
(I added this to the "local" block since I do my development on a remote server - be sure to only enable this for non-public development / staging servers, as it may cause security issues). If you have a static IP use that instead of the wildcards.
Sources: https://www.yiiframework.com/extension/yiisoft/yii2-debug and https://github.com/yiisoft/yii2-debug/blob/15526e95239fcd53316866f9f32cd5daf3a087e5/src/Module.php#L30
-
When I use
'dev
=> [` which is the name of my dev env, I simply get an errorSetting unknown property: craft\web\Application::dev
- do you know how I would restrict this to my dev environment?– DanielAug 7, 2018 at 13:55
For anyone finding it annoying having to be authenticated to enable the debug bar, particularly when testing in multiple browsers, it’s easy to override this behaviour with a custom module.
Just add the following to your init()
code:
// In dev envs override user debug toolbar prefs based on devMode setting
if (getenv('ENVIRONMENT') === 'dev' && ! Craft::$app->getRequest()->getIsConsoleRequest()) {
$session = Craft::$app->getSession();
$session->set('enableDebugToolbarForSite', Craft::$app->config->general->devMode);
}
The above code toggles the debug bar based on the devMode setting, and only in your dev environment. This is handy as you can quickly set devMode to false to test a production-like response.
Bear in mind that because this calls $session->set
, even if you delete the code, your current session will retain whatever preference you last had set.
2022 Edit: I’m not sure when the above code was broken, but as @drifteaur pointed out in the comments, it is possible to set an X-Debug
header to toggle the toolbar and this can be manipulated via module code too. For instance:
if (getenv('ENVIRONMENT') === 'development' && ! Craft::$app->getRequest()->getIsConsoleRequest()) {
$request = Craft::$app->getRequest();
$request->headers->set('X-Debug', 'enable');
}
This works fine with the current Craft 3.7 release but is untested for Craft 4.
-
Keep in mind this will throw an exception for all Console requests Mar 12, 2019 at 12:46
-
1
-
This no longer seems to work. But setting the X-Debug header to 'enable' (via a header modification browser extension, for example) enables the debug toolbar. See web/Application.php#debugBootstrap() Feb 15, 2021 at 17:08