2016-01-15 67 views
1

顯示工具欄我要永遠顯示開發模式下的工具欄,不僅對錯誤。我有以下方法:始終在開發模式

/** 
* @Route("/", name="homepage") 
*/ 
public function indexAction(Request $request) : JsonResponse 
{ 
    return new JsonResponse($param); 
} 

我運行測試工具欄。這當然會產生一個錯誤,因爲$param和工具欄出現。但是,當我使用return new JsonResponse('aaa');一切正常,並沒有出現工具欄。

如何使工具欄appread即使沒有錯誤?

配置:

framework: 
    templating: 
     engines: ['twig'] 
    router: 
     resource: "%kernel.root_dir%/config/dev/routing.yml" 
     strict_requirements: true 
    profiler: { only_exceptions: false } 

web_profiler: 
    toolbar: true 
    intercept_redirects: true 

AppKernel:

if (in_array($this->getEnvironment(), array('dev', 'test'), true)) { 
      $bundles[] = new Symfony\Bundle\TwigBundle\TwigBundle(); 
} 
+0

默認情況下,它總是在開發,更好地問:「有什麼錯了,我這樣做,工具欄沒有顯示」。 – malcolm

+1

您返回'JsonResponse'實例,因此沒有HTML Symfony可以將工具欄標記插入。 – xabbuh

+0

@ SaschaM78在這種情況下,您鏈接的答案不是正確的答案。 –

回答

4

Symfony的噴射僅在一定的條件下的工具欄中,且僅當該響應是一個html響應。請參閱WebDebugToolbarListener以瞭解它是如何完成的。收聽者looks for the </body> tag並在其之前注入工具欄代碼。

如果聽者注入工具欄成JSON響應,它將使響應無效。

您仍然可以訪問配置文件雖然,因爲探查鏈接包含在響應的X-Debug-Token-Link頭。您還可以在X-Debug-Token標題中找到分析器唯一標識符。

注意,X-Debug-Token-Linkwas introduced in Symfony 2.4。在您只能訪問令牌之前。

+0

非常感謝,實際上我可以通過X-Debug-Token訪問它。 – user99999