我不知道从下面的嵌套数组中提取错误。我想知道我应该使用foreach来获取在树枝中显示的错误数组吗?
"errors" => FormErrorIterator {#1191 ▼
-form: Form {#807 ▼
-config: FormBuilder {#796 ▶}
-parent: Form {#747 ▼
-config: FormBuilder {#828 ▶}
-parent: null
-children: OrderedHashMap {#819 ▶}
-errors: array:1 [▼
0 => FormError {#1185 ▼
-message: "Your first name must be at least characters long"
#messageTemplate: "Your first name must be at least characters long"
#messageParameters: array:2 [▶]
#messagePluralization: 1
-cause: ConstraintViolation {#1196 ▶}
-origin: Form {#807}
}
]
答案 0 :(得分:1)
你有一个小部件:
{{ form_errors(form) }}
答案 1 :(得分:0)
从 TWIG
访问错误显示模板中的所有错误
{{ form_errors(form) }}
特定字段的访问错误
{{ form_errors(form.username) }}
阅读更多:How to get error message of each field from form object in symfony2?