2017-03-02 41 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