Q:

get the role and last_login from user FosuserBundle Symfony

I want to get in my layout the name of role and the date of last_login .
i use Symfony 2.5, and FosuserBundle
So when i use:       
{{ app.user.username }}

i get the name of username, but when i use :
{{ app.user.roles }}

i get array This is quite normal since it is array.
  <div class="floatleft marginleft10">
                    <ul class="inline-ul floatleft">
                        <li>Espace {{ app.user.username }}</li>

                        <li><a href="{{ path('fos_user_security_logout') }}">Logout</a></li>
                    </ul>
                    <br />               
                    <span class="small grey">Last Login: {{ app.user.last_login }}</span>
                </div>

when i added {{ app.user.last_login }} i get exception :
       Method "last_login" for object "My\testBundle\Entity\Collaborateur" does not exist in MytestBundle::layout2.html.twig 

any help please !!

A:

Role
You will (as you stated) be returning an array from app.user.roles or $user->getRoles() so you should treat it like an array.
For a list..
<ul>
    {% for role in app.user.roles %}
        <li>{{ role }}</li>
    {% endfor %}
</ul>

Or comma separated..
{% for role in app.user.roles %}
    {{ role }}{% if false == loop.last %}, {% endif %}
{% endfor %}

Last Login
The field is..
/**
 * @var \DateTime
 */
protected $lastLogin;

So you should be using..
{{ app.user.lastLogin }}

And probably with the date filter..
{{ app.user.lastLogin|date('Y-m-d H:i:s') }}

