문제

I have seen so far a Twig method to know the user privilege

{% if is_granted('ROLE_USER') %}

but nothing about getting authentified user informations, without passing the object in every single controller actions.

Before looking for how to pass a global variable to my layout, I'd rather know if there is any "standard" way to access my security provider user objects (at least the username, and database informations for entity users) in my layout or in any template covered by a firewall.

도움이 되었습니까?

해결책

Try {{ app.user }}.

The app template variable provides you access to a lot of the global variables that you'd expect, like request, session, security, etc. Check out the source code for more info.

One thing you should be aware of is that while the GlobalVariables class provides getters for all of the variables, Twig is smart enough to know how to deal with the short form, so that {{ app.user }} is equivalent to {{ app.getUser() }}

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top