Symfony2: how to redirect to a specific page when the user is not allowed access to the URL pattern

I am trying to figure out how to redirect to a specific page (which in my case is a payment page) for a user who does not have a valid subscription.

I know that I can do this by putting the isGranted test request in all my actions, but I don’t like this solution, because it seems like a big waste of time, given the number of actions that I have.

I looked through the parameters of firewall.access_denied_url, but I do not want to bind AccessDenied to the payment page, because, for example, access to the administrator page is denied to any user who does not have ROLE_ADMIN, and redirecting to the payment page does not make any sense.

I already have a voter that checks if the user is valid or not and grants access in this case, but how can I use this voter when the user tries to reach a specific template and redirect him / her when access is denied?

Thanks in advance!

+5
source share
2 answers

In app / config / security.yml add under protection:

access_denied_url: / foo / error403

Symfony then redirects all pages to which the user cannot access the page / foo / error403.

+6
source

You can use JMSAopBundle .

From the documentation:

This kit adds AOP features to Symfony2.

, (, ) , .

, . .

+1

All Articles