作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用Symfony 3.1。我确实按照以下网址实现了自定义错误页面模板。
(http://symfony.com/doc/current/controller/error_pages.html#custom-exception-controller)。
我在同一位置创建所有文件:
app/
└─ Resources/
└─ TwigBundle/
└─ views/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
├─ error.html.twig # All other HTML errors (including 500)
├─ error404.json.twig
├─ error403.json.twig
└─ error.json.twig # All other JSON errors (including 500)
twig:
exception_controller: TwigBundle:ExceptionController:showException
<h1>Page not found</h1>
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
{# ... #}
{% endif %}
<p>
The requested page couldn't be located. Checkout for any URL
misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.
</p>
In case you need them, the Ex
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in D:\xampp\htdocs\PROJECT_NAME\var\cache\prod\appProdUrlMatcher.php:922 Stack trace: #0 D:\xampp\htdocs\PROJECT_NAME\var\cache\prod\classes.php(1744): appProdUrlMatcher->match('/jkhjjkohuioioi...') #1 D:\xampp\htdocs\PROJECT_NAME\var\cache\prod\classes.php(1613): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #2 D:\xampp\htdocs\PROJECT_NAME\var\cache\prod\classes.php(2758): Symfony\Component\Routing\Router->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher)) #4 D:\xampp\htdocs\PROJECT_NAME\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\WrappedListener.php(61): call_user_func(Array, Object(Symfony\Component\HttpKernel\ in D:\xampp\htdocs\PROJECT_NAME\var\cache\prod\classes.php on line 3328
最佳答案
在第一个中,您需要在以下位置创建新的错误模板:/YOUR_PROJECT_FOLDER/app/Resources/TwigBundle/views/Exception/
例如,创建一个: error.html.twig 处理所有错误
在第二个中,您必须为错误 View 编写一些模板内容。
为了进行实验,请将这些内容放入我们的error.html.twig中:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Error test. An Error Occurred: {{ status_text }}</title>
</head>
<body>
<h1>WooHoo! Now you can see new error template</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
</body>
</html>
/YOUR_PROJECT_FOLDER/app/config/routing_dev.yml
(它可以已经存在)
# app/config/routing_dev.yml
_errors:
resource: "@TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
/app_dev.php/_error/418
其中
418
只是错误状态代码
error404.html.twig
来仅处理404错误。或者,您可以为xml响应500错误创建
error500.xml.twig
。
关于symfony - 如何在symfony 3.1中自定义错误页面模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257640/
我是一名优秀的程序员,十分优秀!