dou12352 2014-11-17 10:35
浏览 119

404和500状态的自定义错误页面

I want to have different error pages for 404 and 500 errors. How can I do that?

I work in production environment only. I overrided twig error templates and put them in app/Resources/TwigBundle/views/Exception folder.

I wanted to create two files there:

error404.html.twig
exception_full.html.twig

This way if it's 404 it would open the first file, and in any other case it would open the other one.

I have a couple of problems though:

  • the first file never opens on 404 error...only the second, and symfony default if it doesn't exist
  • I can't extend the base template in neither of them ({% extends '::layout.html.twig' %}), because if I use it the template just doesn't load

Any suggestions?

Thanks!

  • 写回答

1条回答 默认 最新

  • douxing6434 2014-11-17 16:16
    关注

    change your exception_full.html.twig file name to just error.html.twig. It is working for me like this. I have several error4xx files, and if I haven't defined a specific code and that exception occurs, it will display the error.html.twig view.

    As for not showing your base template, where exactly is your base template located? If you are using the syntax '::layout.html.twig' then layout.html.twig must be located at app/Resources/views/layout.html.twig. If that is the case, then you should get an error that explains why it won't load.

    take a look at the docs for a bit more info.

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助