Web Debug Toolbar and Profiler

Right now, there's no floating web debug toolbar on our pages. That's one of the best features of Symfony, and so I want it in my micro-edition too.

Instead of getting a lot of features automatically, we need to enable things one-by-one when and if we need them. The same is true for the web debug toolbar: it comes from the WebProfilerBundle. This lives in our project, but it's not enabled yet. Add it in AppKernel down below the others:

27 lines AppKernel.php
... lines 1 - 5
class AppKernel extends Kernel
public function registerBundles()
... lines 10 - 16
$bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
... lines 18 - 19
... lines 21 - 25

Next, head into config.yml - we need a little bit of configuration. Add a web_profiler key with a toolbar option. Set this to %kernel.debug%:

12 lines config/config.yml
... lines 1 - 9
toolbar: %kernel.debug%

That's a special parameter that's equal to the debug argument we pass to AppKernel in index.php:

24 lines web/index.php
... lines 1 - 8
$debug = true;
... lines 10 - 17
$kernel = new AppKernel($env, $debug);
... lines 19 - 24

Mostly, this flag is used to hide or show errors. But for now, we'll also use it to decide if the web debug toolbar should show up or not.

Also, under framework, add a profiler key with an enabled option that we'll also set to %kernel.debug%:

12 lines config/config.yml
... lines 2 - 6
enabled: %kernel.debug%
... lines 9 - 12

We have debug set to true, so try it! No toolbar yet - just this nice error:

Unable to generate a URL for the named route "_wdt" as such
route does not exist.

This is the error you usually get if you're generating a URL to a route, but you're using a bad route name. The web debug toolbar and profiler are fueled by real Symfony routes, and those routes need to be included for this all to work. On the Standard Edition, I already have the app/config/routing_dev.yml file open, because we need to copy the top two entries. Find config/routing.yml and paste those there:

12 lines config/routing.yml
... lines 1 - 4
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler

Try one more time. There's the toolbar, with all of the goods we love.

Leave a comment!

  • 2017-08-23 Nina

    Thanks for the detailed explanation!

  • 2017-08-23 Victor Bocharsky

    Hey Nina,

    Well, in this chapter there's no any important reason do it with "$bundles[]" instead of putting it into $bundles array on initialization. But answer is simple: this bundle is related to development mode and should not be used in production. That's why we separate it from other bundles which we use in both development and production. In shorts, we can easily exclude it for production later. But technically, there're no any difference for PHP interpreter ;)

    It could look differently if you upgrade Composer packages. But if you will use our locked dependencies, i.e. download course code and execute "$ composer install" instead of upgrade - it will look the same I think.

    "%" is a special character when Symfony parse YAML files which means we're referencing to a parameters, i.e. "%kernel.debug%" means we're referencing to the "kernel.debug" parameter, so when Symfony parses this YAML file it will be replaced with its real value.


  • 2017-08-23 Nina


    Why we use:
    $bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();

    And not put new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    шnto an existing array $bundles in the AppKernel.php?
    Why my tool bar looks different from you show in the lesson

    What mean % around %kernel.debug%?
    What function they perform?

  • 2015-10-22 Roberto

    Of course, I find the answer right after posting my comment... :)
    We just need the proper .htacces file in web folder.

  • 2015-10-22 Roberto

    Nice tuts!
    But got a 404 on "_wdt/6d6966" while refreshing the index page.

    I have _wdt route definition below "app_annotations" in config/routing.yml.

    Any idea?