0

As it was answered on this question How do I get the entity that represents the current user in Symfony2? That shows you how to do it on a controller, but how do you do get the actual user entity on a php template without having to send it on a parameter to the template?

The far as I get was:

$app->getSession()->getUsername();

But that just gave a raw var with the user name, i want the user entity.

Community
  • 1
  • 1
DomingoSL
  • 14,920
  • 24
  • 99
  • 173
  • possible duplicate of [FOSuserbundle Symfony2 accessing user data on any page](http://stackoverflow.com/questions/7463650/fosuserbundle-symfony2-accessing-user-data-on-any-page) – moonwave99 Jul 31 '13 at 08:47
  • 1
    Definitly not a duplicate of the link you added – sf_tristanb Jul 31 '13 at 09:24
  • @moonwave99 please read the question before putting a duplicate alert. This is for PHP templates, the other one is for TWIQ templates – DomingoSL Jul 31 '13 at 11:03

1 Answers1

4

You can use $app->getUser() in the php template and app.user in the twig template.

See: http://symfony.com/doc/current/book/security.html

cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
Benjamin Lazarecki
  • 2,950
  • 1
  • 20
  • 27