Skip to content

Document **not** to use is_granted in templates: "How to Customize Error Pages" #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
weaverryan opened this issue Dec 31, 2012 · 7 comments
Labels
good first issue Ideal for your first contribution! (some Symfony experience may be required)

Comments

@weaverryan
Copy link
Member

For Symfony 2.1, your error template can not use is_granted in your Twig template. For details, see symfony/symfony#5320. We should document this clearly, especially since this is difficult to debug and you probably won't see it until you're on production.

@stof
Copy link
Member

stof commented Dec 31, 2012

Well, in some cases, you can, but not always. A safe way to use it is {% if app.user is not null and is_granted() %} as app.user will return null when there is no token or when the user is anonymous

@adamquaile
Copy link

@stof I understand this (old) issue is down to the order of the listeners, but you say "in some cases you can" - in what cases would is_granted work?

@wouterj
Copy link
Member

wouterj commented Oct 1, 2015

@adamquaile when there is an error page that happend before initializing Security (in the referenced PR, there was an issue with the router, which is executed before the firewall, so it couldn't be used).

@adamquaile
Copy link

@wouterj Yeah, I get that. I'm wondering in what cases the firewall is executed before the routing exception..?

Well, in some cases, you can [use is_granted], but not always

I get why you can't, but why would it ever work? Would this only apply if we manually threw the not found exception from a controller?

@xabbuh
Copy link
Member

xabbuh commented Oct 1, 2015

By the way, with Symfony 2.8 you will be able to always use is_granted() without doing this check (see symfony/symfony#15953).

@wouterj
Copy link
Member

wouterj commented Oct 1, 2015

@adamquaile not all exceptions happen in the routing. The "in some cases" is about the other errors not happening in routing

@adamquaile
Copy link

@wouterj Okay. Got it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Ideal for your first contribution! (some Symfony experience may be required)
Projects
None yet
Development

No branches or pull requests

5 participants