简体   繁体   中英

How to customize 403 error exception in symfony2?

I have put the following files in

/app/Resources/TwigBundle/views/Exception

error.html.twig, error.json.twig , error403.json.twig, error404.json.twig

But still i am not able to get those templates

I want it for access denied exception

 Token does not have the required roles.
403 Forbidden - AccessDeniedHttpException
1 linked Exception:

    AccessDeniedException »

If i were you i'd customize the error403.html.twig in the following folder app/Resources/TwigBundle/views/Exception/error403.html.twig

I guess you've mistaken the format of this file ( json instead of html )

Also, make sure that you've cleared the cache ( php app/console ca:cl ) and that you are in prod environement.

A more recent update for this. I found that in Symfony 2.8.x, the template you need to override is called exception.html.twig .

I did so by adding the following file in this path.

app/Resources/TwigBundle/views/Exception/exception.html.twig

You can find the original in this folder here:

vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception

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