我有一个包含{{ render(controller(...) }}
代码的模板。它工作正常,直到我尝试处理404错误。我得到The security context contains no authentication token
试图调用控制器操作,即使它返回的结果包含单行文本而不使用会话或任何东西。
答案 0 :(得分:0)
检查您是否呈现模板(不仅是子请求,而且容器和附加包括以及)包含对{{ app.user }}
的任何引用。引自官方文件:
您不得在错误页面(或使用的布局)中使用is_granted 你的错误页面),因为路由器在防火墙之前运行。如果 路由器抛出异常(例如,当路由没有时) 匹配),然后使用is_granted将抛出另一个异常。您可以 通过说{%if app.user和is_granted('...')安全地使用is_granted %}。
http://symfony.com/doc/current/cookbook/controller/error_pages.html