从树枝模板中的FormView获取全局表单错误 [英] Get global form errors from the FormView in twig template
问题描述
为了在树枝模板中渲染表单错误,只需要使用 form_errors
树枝宏而不会产生差异,如果它是全局表单错误或字段错误。 p>
但是在我的情况下,全局错误并不像字段错误,所以我不能使用 form_errors
这两种情况下的树枝宏。我决定使用宏来处理字段错误&我想从 Symfony \ Component \Form \FormView
对象中获取全局表单错误。我们的目标是迭代树枝模板中的全局错误&渲染它们就像我想要的。
实际上,我没有找到symfony2文档上的任何资源可以帮助我。
最后,我自己找到了解决方案。对于想要做同样事情的人来说,解决方案是调用 $ formView-> get(errors)
,它会给你一个 FormError
For rendering form errors in a twig template, you just have to use the form_errors
twig macro without difference if it is a global form error or a field error.
But in my case, a global error is not rendered like a field error, so I can't use the form_errors
twig macro for the two cases. I decide to use the macro for the field error & I would like to get the global form errors from the Symfony\Component\Form\FormView
object. The goal is to iterate the global errors in the twig template & render them like I want.
Actually, I don't find any ressources on the symfony2 documentation which can help me.
Finally, I found the solution by myself. For the people who want to do the same thing, the solution is to call $formView->get("errors")
which gives you an array of FormError
这篇关于从树枝模板中的FormView获取全局表单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!