7

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.

9

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

|improve this answer|||||
  • I did that as well but the front end console won't show up but the cp does. – Mark H. Mar 9 '18 at 19:06
  • Any way to enable this for secondary sites, using the Control Panel? – 4midori Nov 6 '19 at 22:19
  • What do you mean by secondary sites? – Robin Schambach Nov 6 '19 at 22:20
  • I don't really see an issue. You can have the debug toolbar for whatever site you want – Robin Schambach Nov 7 '19 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. – billythekid Dec 5 '19 at 14:53
4

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

|improve this answer|||||
  • When I use 'dev => [` which is the name of my dev env, I simply get an error Setting unknown property: craft\web\Application::dev - do you know how I would restrict this to my dev environment? – Daniel Aug 7 '18 at 13:55
3

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.

|improve this answer|||||
  • Keep in mind this will throw an exception for all Console requests – Robin Schambach Mar 12 '19 at 12:46
  • So it does, I’ve added a fix for that. – Dom Stubbs Mar 12 '19 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.