如何在 Symfony 的自定义错误页面中显示异常文本? [英] How to display exception text in a custom error page on Symfony?

查看:24
本文介绍了如何在 Symfony 的自定义错误页面中显示异常文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Symfony,并按照 Symfony 文档的说明创建了一个自定义错误页面.

I'm working on Symfony and I created a custom error page, following the instruction of the Symfony documentation.

所以,我有我的应用程序/Ressources/TwigBundle/views/Exception/error.html.twig 文件.它工作正常,但在我的错误视图中,我想显示异常文本,以便如果我在控制器中执行此操作:

So, I have my app/Ressources/TwigBundle/views/Exception/error.html.twig file. It works fine, but in my error view, I want to display the Exception text, so that if I do this in a controller:

throw new \Exception('Ooops !');

...我可以显示值 'Ooops !'在我的树枝视图中.

...i can display the value 'Ooops !' in my Twig View.

有人知道哪个 Twig 变量有这个信息吗?

Do someone knows which Twig variable have this information ?

推荐答案

我终于找到了答案:异常消息可以通过 Twig 错误模板中的 exception.message 变量轻松访问.

I finally found the answer : the Exception Message is simply accessible by the exception.message variable in the Twig error template.

这篇关于如何在 Symfony 的自定义错误页面中显示异常文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆