如何在Symfony2开发环境中显示404错误页面

如何在Symfony2开发环境中显示404错误页面,symfony,development-environment,Symfony,Development Environment,我想在开发环境中使用404页面。我使用以下文件自定义404:app/Resources/TwigBundle/views/Exception/error.html.twig 此产品url工作正常:mysite.com/404 但是这个mysite.com/app_dev.php/404抛出一个NotFoundHttpException并给我一个dev debug页面 是否可以显示错误页面而不是调试页面 更新: 官方文档中现在有一章是关于这一点的:您需要在开发时覆盖exception_full.h

我想在开发环境中使用404页面。我使用以下文件自定义404:app/Resources/TwigBundle/views/Exception/error.html.twig

此产品url工作正常:
mysite.com/404

但是这个
mysite.com/app_dev.php/404
抛出一个NotFoundHttpException并给我一个dev debug页面

是否可以显示错误页面而不是调试页面

更新:


官方文档中现在有一章是关于这一点的:

您需要在开发时覆盖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()函数。

要显示错误页面,请在web/app\u dev.php中将第二个参数更改为
false

$kernel = new AppKernel('dev', false);
测试完所需内容后,将其更改回原处


更新

感谢@user2019515指出这一点-现在(2.3及更高版本)中有一个指向的链接,我上面写的方法不应使用。

在开发环境中,您可以使用以下路径:

/_error/404.html
其中,
404
是要测试的错误代码,
html
是请求的格式。 要能够使用此功能,请确保您的
routing\u dev.yml
文件中有以下条目:

# app/config/routing_dev.yml
_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

您还可以将路由添加到路由\ u 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
?这是我的一天。谢谢你,克里斯。在Symfony 2.1中,路径似乎是:
vendor/Symfony/Symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
我必须
cache:clear
才能覆盖
exception\u full.html.twig
(SF2.1)。如果你想在dev env中测试错误页面,这绝对是一种方法,因为他们将在产品中。根据文档,你不应该这样做:谢谢你指出这一点,@user2019515。虽然我现在记不清了,但当我写下这个答案时,文档中没有关于WebfactoryExceptionsBundle的内容——它出现在2.3文档中。