Symfony 2 表单主题中冒泡错误和字段错误的区别? [英] Distinguish between bubbled errors and field errors in Symfony 2 form theme?

查看:30
本文介绍了Symfony 2 表单主题中冒泡错误和字段错误的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何区分字段错误和冒泡(表单)错误?AFAIK 唯一控制它的 block 是:

How can i distinguish between field errors and bubbled (form) errors? AFAIK the only block that controls this is:

{% block field_errors %}
{% spaceless %}
    {% if errors|length > 0 %}
    <ul>
        {% for error in errors %}
        ...
        {% endfor %}
    </ul>
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}

我认为我不能依赖 errors|length:通常字段错误为 1,但表单错误也可以为 1 :(

I think i can't rely on errors|length: usually it's 1 for field errors, but can be 1 also for form errors :(

推荐答案

在我看来,默认情况下您无法区分这些错误.但是你可以扩展基本的 FormError类并添加一些属性,这将定义错误出现的确切位置.

To me it looks like by default you are unable to separate these errors. But you can extend the basic FormError class and add some property, which will define the exact place where error appeared.

这篇关于Symfony 2 表单主题中冒泡错误和字段错误的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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