替换symfony2访问被拒绝模板

Using Symfony2.3.4, PHP5.6.3 and Twig.

See, this is the template used by symfony everytime a user tries to access a url and it does not pass the access control set in the security.yml file. All I want is to redirect the user to a template of my creation/choosing.

If I were restricting the user's access in a PHP class, sure, I could ask for its role/permissions and decide from there but I want to use the access control I have already set in my security.yml file, say like a global .html.twig file to replace the one below.

Symfony template

The page you see is the debug version of the 'error' page... it should never be used in production ... because it gives away wayy too much information ...

i am assuming you just want to show your users a simple 403 error message ... and not a stack trace of the exception.

so use the url without the app_dev.php ... to see what everyone else will see... not only the devs.

the template lives in vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\Resources\views\Exception\error.html.twig In the vendors directory under symfony

to replace it copy the file and put it in your app directory

app/Resources/TwigBundle/views/Exception/error.html.twig and change it to something cool...

clear the cache php app/console cache:clear -e prod

you should be good to go... :)

ref SF Cookbook