Symfony2 is_granted('IS_AUTHENTICATED_FULLY') during 404 error page display, causing ResourceNotFoundException

前端 未结 3 1923
天命终不由人
天命终不由人 2020-12-29 07:09

I have setup custom error pages to display for certain HTTP errors in the folder:

app/Resources/TwigBundle/views/Exception/

The 403 page (<

3条回答
  •  抹茶落季
    2020-12-29 07:36

    If symfony < 2.8 :

    {% if app.user is not null and is_granted('ROLE_ADMIN') %}
    

    See : https://github.com/symfony/symfony-docs/issues/2078

    Edit from Dec 17 '15:

    This is no longer needed since 2.8,

    {% if is_granted('ROLE_ADMIN') %}
    

    works fine now.

    source: http://symfony.com/blog/new-in-symfony-2-8-dx-improvements#allow-to-check-for-security-even-in-pages-not-covered-by-firewalls

提交回复
热议问题