这是我的页面:error404.html.twig 作为文档 Example 404 Error Template
{# templates/bundles/TwigBundle/Exception/error404.html.twig #}
{% extends 'base.html.twig' %}
{% block body %}
<h1>Page not found</h1>
<p>
The requested page couldn't be located. Checkout for any URL
misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.
</p>
{% endblock %}
这是我的页面 config/routes/dev/twig.yaml
# config/routes/dev/twig.yaml
_errors:
resource: '@TwigBundle/Resources/config/routing/errors.xml'
prefix: /_error
这是我的页面 config/packages/twig.yaml
# config/packages/twig.yaml
twig:
exception_controller: App\Controller\ExceptionController::showException
我应该怎么做才能使它起作用?
错误是: :
服务.yaml:
最佳答案
如果您处于 Debug模式并且不是 404 页面,您会得到 NotFoundHttpException
那么一切都很好,因为这是记录在案的和期望的行为,如下所述:https://symfony.com/doc/current/controller/error_pages.html
In the development environment, Symfony catches all the exceptions and displays a special exception page
要绕过这个并实际看到您的自定义 404 页面,您需要通过特殊途径访问模板:
http://localhost/index.php/_error/404
关于symfony - 如何显示 404 错误页面而不是 Symfony4 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52770358/