Jiew Meng
Jiew Meng

Reputation: 88317

Symfony 2 Access Control to Objects in View

In views, I can use

if ($view['security']->isGranted('ROLE_ADMIN')) :

To check if the user has a certain role. But what about objects?

For example: when a user is viewing his/her post, I want to show an edit/delete button

Upvotes: 1

Views: 1279

Answers (1)

Kasheen
Kasheen

Reputation: 5411

In a twig template you can use the is_granted function, see Access control in templates for more information.

To apply it to ACL you can just do:

{% if is_granted('EDIT', post) %}
    Show buttons here
{% endif %}

Upvotes: 3

Related Questions