按照文档http://symfony.com/doc/current/cookbook/controller/error_pages.html,我已经能够为错误添加自己的模板;
app
|- Resources
| | - TwigBundle
| | |- view
| | | |- Exception
| | | | |- exception.html.twig
| | | | |- error.html.twig
| | | | |- error400.html.twig
| | | | |- error404.html.twig
| | | | |- error500.html.twig
| | | |- layout.html.twig
|- config
这非常有效,但如何保持堆栈跟踪和我的开发环境的详细错误?
在制作中我希望使用自己的模板,在开发环境中我希望使用Symfony2自己的模板。
答案 0 :(得分:3)
app
|- Resources
| |- TwigBundle
| | |- view
| | | |- Exception
| | | | |- exception.html.twig
| | | | |- error.html.twig
| | | | |- error400.html.twig
| | | | |- error404.html.twig
| | | | |- error500.html.twig
| | | |- layout.html.twig
| |- view
| | |- my_custom_error_layout.html.twig
|- config
my_custom_error_layout.html.twig
<!DOCTYPE>
<html>
<head>
</head>
<body>
html, block, whatnot go here
</body>
</html>
error400.html.twig
{% extends "::my_custom_error_layout.html.twig" %}
{% block body %}
details or fixed message go here...
{% endblock %}
答案 1 :(得分:1)
在我们最近的项目中,我们实施了如上配置的自定义ExceptionListener:
<!-- Acme Exception Listener -->
<service id="kernel.listener.customer_area_exception_listener" class="AcmeSecurityBundle\Listener\AcmeExceptionListener">
<argument type="service" id="templating" />
<argument>%acme.exceptions.debug%</argument>
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
</service>
使用参数(来自parameters.yml
)来区分env。
异常监听器知道如何渲染每种类型的异常,自定义异常也。
希望这个帮助