I have followed the 'How to load Security Users from the Database (the Entity Provider)' recipe from the Symfony2 cook book (http://symfony.com/doc/current/cookbook/security/entity_provider.html), except I am not using the Custom Entity Provider - which means my User class is using lazy loading for the roles.
The firewall/access control in the security all works fine. I have some routes that only ROLE_ADMIN users can access and some that ROLE_USER users can access - these work fine.
The problem is that in my base template, I have a bar that is displayed like:
<p>Logged in as: {{ app.user.username }} {% if is_granted('ROLE_ADMIN') %}| <a href="{{ path('bassettprovidentia_skeleton_admindashboard') }}">Admin area</a> {% endif %}| <a href="#">Settings</a> | <a href="{{ path('bassettprovidentia_skeleton_logout') }}">Log out</a></p>
Even though my user has the ROLE_ADMIN role in the database (and can access URLs that are restricted to that role), the "Admin area" link is not being displayed!
In the same form, I have this:
<p>Roles: {% for role in app.user.roles %}{{ role.name }} [{{ role.role }}]{% if not loop.last %}, {% endif %}{% endfor %}</p>
It works fine! All of the roles which the user has are displayed!
What am I doing wrong?
Is the lazy-loading to blame?
It isn't causing problem's elsewhere.