我想从开发环境下处理404页面。我使用以下文件进行自定义: app/Resources/TwigBundle/views/Exception/error.html.twig
这个网址在生产环境下能够正常工作: mysite.com/404
但是这个网址 mysite.com/app_dev.php/404
抛出NotFoundHttpException并给我开发调试页面。
是否可以显示错误页面而不是调试页面?
更新:
现在官方文档有一章关于此问题:测试开发期间的错误页面
我想从开发环境下处理404页面。我使用以下文件进行自定义: app/Resources/TwigBundle/views/Exception/error.html.twig
这个网址在生产环境下能够正常工作: mysite.com/404
但是这个网址 mysite.com/app_dev.php/404
抛出NotFoundHttpException并给我开发调试页面。
是否可以显示错误页面而不是调试页面?
更新:
现在官方文档有一章关于此问题:测试开发期间的错误页面
false
。$kernel = new AppKernel('dev', false);
在测试完所需内容后,请将其改回。
更新
感谢@user2019515指出-现在(2.3及以上版本)在Symfony文档中有一个到WebfactoryExeptionsBundle的链接,上面提到的方法不应该使用。
从Symfony 2.6版本开始在开发环境中,您可以使用以下路由:
/_error/404.html
其中404
是要测试的错误代码,html
则是请求的格式。
要使用此功能,请确保您的routing_dev.yml
文件中有以下条目:
# app/config/routing_dev.yml
_errors:
resource: "@TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
你需要在开发环境中重写 exception_full.html.twig 模板。
app/Resources/TwigBundle/views/Exception/exception_full.html.twig
Symfony2使用此模板在开发过程中为您提供尽可能多的调试信息。
当内核处于调试模式时,Symfony2将使用exception_full.html.twig,否则它将使用您覆盖的特定模板。
有关更多详细信息,请参见vendor/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php,具体是showAction()和findTemplate()函数。
vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
- arminrosucache:clear
命令以使 exception_full.html.twig
能够被覆盖(SF2.1) - Pierre de LESPINAY同时,您可以将路由添加到您的routing_dev.yml文件中。
error404:
path: /404
defaults:
_controller: FrameworkBundle:Template:template
template: TwigBundle:Exception:error404.html.twig
error500:
path: /500
defaults:
_controller: FrameworkBundle:Template:template
template: TwigBundle:Exception:error500.html.twig
app/Resources/TwigBundle/views/Exception/exception.html.twig
? - meze