简体   繁体   English

没有注入Symfony2调试工具栏Symfony 2.8

[英]Symfony2 debug toolbar is not injected Symfony 2.8

I am trying to make the web debug bar appear in Symfony 2.8 and I somehow cannot make it work. 我试图使Web调试栏出现在Symfony 2.8中,但我不知如何使其无法工作。

My template has a closing Tag. 我的模板有一个结束标记。 Also WebDebugToolbarListener gets invoked but aborts on this condition: WebDebugToolbarListener也被调用,但在这种情况下中止:

     if (self::DISABLED === $this->mode
        || !$response->headers->has('X-Debug-Token')
        || $response->isRedirection()
        || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
        || 'html' !== $request->getRequestFormat()
        || false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
    ) {
        return;
    }

    $this->injectToolbar($response, $request);

I debugged and found that "X-Debug-Token" is NEVER included in the headers. 我调试后发现标题中从未包含“ X-Debug-Token”。 That's why injectToolbar method is never invoked. 这就是为什么永远不会调用injectToolbar方法的原因。 When I comment the specific line || !$response->headers->has('X-Debug-Token') 当我评论特定行|| !$response->headers->has('X-Debug-Token') || !$response->headers->has('X-Debug-Token') the toolbar would show up, however I receive the Exception: || !$response->headers->has('X-Debug-Token')工具栏将显示,但是我收到异常:

"Parameter "token" for route "_wdt" must match "[^/]++" ("" given) to generate a corresponding URL." “路由“ _wdt”的参数“令牌”必须与“ [^ /] ++”(给定的“”)匹配,以生成相应的URL。”

Also it's obviously the wrong way dealing with this problem. 显然,这是处理此问题的错误方法。

What am I doing wrong? 我究竟做错了什么? I am out of ideas. 我没主意。

Here is what I have configured: 这是我配置的:

#config_dev.yml
framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"
        strict_requirements: true
profiler: { only_exceptions: true }

web_profiler:
    toolbar: true
    intercept_redirects: false
    position: bottom

//app_dev.php
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

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

//AppKernel.php
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}

#routing_dev.yml
_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

Apparently I had to enable profiler explicitely (which sets the X-Debug-Token). 显然,我必须显式地启用探查器(设置X-Debug-Token)。 RTM for the win. RTM取胜。 I had never done this in the past though. 我过去从未这样做过。

The key is to set only_exceptions: false . 关键是设置only_exceptions: false Otherwise the profiler would not collect any data and also won't set the X-Debug-Token and thus the toolbar would not attach. 否则,探查器将不会收集任何数据,也不会设置X-Debug-Token,因此工具栏将不会附加。 I have set this flag to true in the past because my cache directory was growing quite rapidly. 过去,我将此标志设置为true,因为我的缓存目录增长非常快。

The enabled Flag is set to true for dev and test environments by default. 默认情况下,对于开发和测试环境,已enabled标志设置为true。

#config_dev.yml
framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"
        strict_requirements: true
    profiler: { only_exceptions: false }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM