简体   繁体   中英

Symfony2 - How to only show specific elements to ROLE_USER

I am trying to hide CRUD elements in TWIG so that it only appears for the specified ROLE_USER.

Right now I am using IS_AUTHENTICATED REMEMBERED which works against anonymous users but other logged in users are still able to see this.

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
    <li>
        <a href="">
        Create a new entry
        </a>
    </li>
{% endif %}

I want to only show this to the specific ROLE_USER that I have set in the access_control in security.yml and the controller. For instance the code above should only be shown to ROLE_USER1 .

What is the command to do this in Twig?

Use is_granted('ROLE_USER1')

{% if is_granted('ROLE_USER1') %}
    <li>
        <a href="">
        Create a new entry
        </a>
    </li>
{% endif %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM