我正在尝试在404错误页面中获取登录用户的用户名,如symfony文档所说;
{# app/Resources/TwigBundle/views/Exception/error404.html.twig #}
{% extends 'base.html.twig' %}
{% block body %}
<h1>Page not found</h1>
{# example security usage, see below #}
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
IS_AUTHENTICATED_FULLY: {{ app.user.username }}
{% endif %}
{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
IS_AUTHENTICATED_REMEMBERED: {{ app.user.username }}
{% endif %}
{% if app.user %}
app.user: {{ app.user.username }}
{% endif %}
<p>
The requested page couldn't be located. Checkout for any URL
misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.
</p>
{% endblock …
Run Code Online (Sandbox Code Playgroud)