doutong2132
2016-01-15 11:17
浏览 97
已采纳

始终在开发模式下显示工具栏

I want to always display the toolbar in dev mode, not only on errors. I have the following method:

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

that I run to test the toolbar. This generates an error of course because $param and the toolbar appears. But when I use return new JsonResponse('aaa'); everything works and the toolbar does not appear.

How to make the toolbar appread even without errors?

config:

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();
}

图片转代码服务由CSDN问答提供 功能建议

我希望始终以开发模式显示工具栏,而不仅仅是错误。 我有以下方法:

  / ** 
 * @Route(“/”,name =“homepage”)
 * / 
 npublic function indexAction(Request $ 请求):JsonResponse 
 {
返回新的JsonResponse($ param); 
} 
   
 
 

我运行以测试工具栏。 这会产生错误,因为 $ param 会出现工具栏。 但是,当我使用返回新的JsonResponse('aaa'); 时,一切正常,工具栏也不会出现。

如何使工具栏显示即使没有错误?

config:

  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 [] =新的Symfony \ Bundle \ TwigBundle \ TwigBundle(); 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douqi2804 2016-01-15 12:17
    最佳回答

    Symfony injects the toolbar only in certain conditions, and only if the response is an html response. See the WebDebugToolbarListener to learn how it's done. The listener looks for the </body> tag and injects the toolbar code before it.

    If the listener injected the toolbar into a json response, it would make the response invalid.

    You can still access the profile though, as the profiler link is included in the X-Debug-Token-Link header of the response. You can also find the profiler unique identifier in the X-Debug-Token header.

    Note that the X-Debug-Token-Link header was introduced in Symfony 2.4. Before you could only access the token.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题