duanhao5038 2016-06-06 18:57
浏览 44
已采纳

替换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

  • 写回答

1条回答 默认 最新

  • dpd3982 2016-06-06 19:39
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64