File tree 2 files changed +8
-28
lines changed
2 files changed +8
-28
lines changed Original file line number Diff line number Diff line change @@ -884,7 +884,7 @@ Access Control in Templates
884
884
...........................
885
885
886
886
If you want to check if the current user has a role inside a template, use
887
- the built-in helper function:
887
+ the built-in `` is_granted() `` helper function:
888
888
889
889
.. configuration-block ::
890
890
@@ -900,20 +900,18 @@ the built-in helper function:
900
900
<a href="...">Delete</a>
901
901
<?php endif ?>
902
902
903
- If you use this function and you are *not * behind a firewall, an exception will
904
- be thrown. Again, it's almost always a good idea to have a main firewall that
905
- covers all URLs (as shown before in this chapter).
906
-
907
- .. caution ::
903
+ .. note ::
908
904
909
- Be careful with this in your base layout or on your error pages! Because of
910
- some internal Symfony details, to avoid broken error pages in the `` prod ``
911
- environment, wrap calls in these templates with a check for `` app. user`` :
905
+ In Symfony versions previous to 2.8, using the `` is_granted() `` function
906
+ in a page that wasn't behind a firewall resulted in an exception. That's why
907
+ you also needed to check first for the existence of the user:
912
908
913
909
.. code-block :: html+twig
914
910
915
911
{% if app.user and is_granted('ROLE_ADMIN') %}
916
912
913
+ Starting from Symfony 2.8, the ``app.user and ... `` check is no longer needed.
914
+
917
915
Securing other Services
918
916
.......................
919
917
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ To override the 404 error template for HTML pages, create a new
96
96
<h1>Page not found</h1>
97
97
98
98
{# example security usage, see below #}
99
- {% if app.user and is_granted('IS_AUTHENTICATED_FULLY') %}
99
+ {% if is_granted('IS_AUTHENTICATED_FULLY') %}
100
100
{# ... #}
101
101
{% endif %}
102
102
@@ -124,24 +124,6 @@ store the HTTP status code and message respectively.
124
124
for the standard HTML exception page or ``exception.json.twig `` for the JSON
125
125
exception page.
126
126
127
- Avoiding Exceptions when Using Security Functions in Error Templates
128
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129
-
130
- One of the common pitfalls when designing custom error pages is to use the
131
- ``is_granted() `` function in the error template (or in any parent template
132
- inherited by the error template). If you do that, you'll see an exception thrown
133
- by Symfony.
134
-
135
- The cause of this problem is that routing is done before security. If a 404 error
136
- occurs, the security layer isn't loaded and thus, the ``is_granted() `` function
137
- is undefined. The solution is to add the following check before using this function:
138
-
139
- .. code-block :: twig
140
-
141
- {% if app.user and is_granted('...') %}
142
- {# ... #}
143
- {% endif %}
144
-
145
127
.. _testing-error-pages :
146
128
147
129
Testing Error Pages during Development
You can’t perform that action at this time.
0 commit comments