Web Debug Toolbar and Profiler
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
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:
// ... 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%
:
// ... lines 1 - 9 | |
web_profiler: | |
toolbar: %kernel.debug% |
That's a special parameter that's equal to the debug
argument we pass to AppKernel
in 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%
:
framework: | |
// ... lines 2 - 6 | |
profiler: | |
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:
// ... lines 1 - 4 | |
_wdt: | |
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" | |
prefix: /_wdt | |
_profiler: | |
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" | |
prefix: /_profiler |
Try one more time. There's the toolbar, with all of the goods we love.
Hi! I have an issue with internal redirects (http504) is there a way to track internal redirects? I know that the profiler toolbar lets me see where the current response was redirected from (if any), but according to the webhost, I exceed the limit of 10 internal redirects... I'm not doing any redirects in my code, so it must be a configuration thing. Either in my symfony setup/routing, or in the nginx setup... Is there any logg or such in symfony that can reveal this to me?