2017-03-02 110 views
0

我想让网页调试栏出现在Symfony 2.8中,而且我无法让它工作。Symfony2调试工具栏没有注入Symfony 2.8

我的模板有一个结束标记。此外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); 

我调试,发现“X-调试令牌”永远不会包含在报头。这就是为什么不会调用injectToolbar方法的原因。当我评论的特定行|| !$response->headers->has('X-Debug-Token')工具栏会显示出来,但是我收到异常:

“参数‘令牌’路由‘_wdt’必须匹配‘[^ /] +’(””中给出)到 生成相应的URL。“

此外,它显然是处理这个问题的错误方式。

我在做什么错?我没有想法。

以下是我已经配置:

#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 

回答

1

显然,我必须明确地让分析器(whic h设置X-Debug-Token)。 RTM为胜利。虽然过去我从来没有这样做过。

关键是要设置only_exceptions: false。否则,分析器不会收集任何数据,也不会设置X-Debug-Token,因此工具栏不会附加。过去我已将此标志设置为true,因为我的缓存目录正在快速增长。

默认情况下,enabled标志在开发和测试环境中设置为true。

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

有趣。我没有一个2.8版本的方便,但我的开箱3.2应用程序工作正常,没有启用:true – Cerad

+0

是的,我错了,关键是将'only_exceptions'设置为false :) – Atan