无法在树枝中显示表单错误

时间:2016-11-28 09:03:07

标签: symfony twig

我不知道从下面的嵌套数组中提取错误。我想知道我应该使用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}
        }
      ]

2 个答案:

答案 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?