【发布时间】:2016-10-26 08:45:21
【问题描述】:
我正在使用 Symfony 3.1。我确实按照下面的 url 来实现自定义错误页面模板。
(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)
我确实创建了一个名为“TwigBundle”的包,并创建了一个名为“TwigBundle\Controller\ExceptionController.php”的控制器文件夹和类
Config.yml
树枝配置
twig:
exception_controller: TwigBundle:ExceptionController:showException
error.html.twig
<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
我已清除缓存并且系统正在 Prod ENV 中运行。 但我仍然没有得到自定义错误模板。
【问题讨论】:
-
您是刚刚创建了自定义模板还是配置了自定义错误控制器?您执行了哪些具体步骤?
-
我只是在上面提到的位置创建自定义模板。注意为控制器做的事情
-
您是否将
@TwigBundle/Resources/config/routing/errors.xml添加到您的开发路由文件中?你不需要重写默认的异常控制器。 -
好的@Stephan Yamilov 你能提供完整的例子吗?