Symfony 2 debug toolbar not showing

2020-07-06 07:02发布

问题:

Symfony debug toolbar doesn't show up, I tried to check a lot of things, but no luck so far.

I am running site on app_dev.php environment, my config_dev.yml has:

web_profiler:
toolbar: true
intercept_redirects: false

app_dev/php doesn't have any IP restrictions, it runs AppKernel with dev environment. Also, AppKernel has the: $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); The main problem could be the HTML, but it has both opening and closing tags. I even tried to remove all the HTML and just leave it with a few HTML and body tags, no luck.

Is there anything else I could try? Maybe some files could be missing? How can I check it? This is not a fresh installed version of Symfony.

回答1:

Make sure you can tick all bullets in this checklist:

  • You are using the dev mode by accessing the page via app_dev.php (True for you)
  • The toolbar inserts itself in pages by looking for a terminating </body> tag on your generated page. If you don't have a </body> tag in your page the toolbar will not appear(as in the above answer). Example twig file as a reference:

    The line {% extends '::base.html.twig' %} will extend app/Resources/views/base.html.twig which injects default <body>...</body> into your custom twig files.

    {% extends '::base.html.twig' %}
    
    {% block body %}
      Hello!
    {% endblock %}
    
  • You have enabled the profiler in AppKernel.php

    public function registerBundles(){
      $bundles = ...
      if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
      ...
      }
    return $bundles;
    }
    
  • You have javascript enabled.

  • Thoroughly Check recently added bundles(specially custom ones). Because Cases like this can cause the problem.



回答2:

Double-check that your <body> tag has a closing </body> tag. In my experience, when the toolbar suddenly disappears it's because the closing body tag is missing due to malformed HTML, or because a controller is returning a Response object with just plain text content.



回答3:

I had this issue with a large(ish) application where the toolbar wasn't being shown on memory heavy pages. Turns out that my php memory limit was being exhausted. I set the memory_limit in my php.ini file to something that would be adequate and that sorted it.



回答4:

if you set the environment as dev it should display debug toolbar at the bottom

edit web/app.php as following;

$kernel = new AppKernel('dev', true);



回答5:

I recently got an old project in SF3.4 and in my case the debug toolbar didn't show up because of the following keys in config.yml file

framework:
    [...]
    profiler:
        collect: false

I commented on those 2 lines and it works again.