小编Fil*_*ilo的帖子

Symfony:在404错误页面中获取登录用户

我正在尝试在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)

symfony twig

2
推荐指数
1
解决办法
1243
查看次数

标签 统计

symfony ×1

twig ×1