我試圖顯示與樹枝中特定form_field相關的錯誤消息,但它不顯示任何內容。與在validation.yml我formType字段{{form_errors(form.fieldName)}}在symfony2.3中不起作用
-\-\Entity\Customer:
properties:
address2:
- NotBlank:
message: 'Testing required'
我已經定義的錯誤,當我打印:
//Controller Class
$validator = $this->get('validator');
$errors = $validator->validate($customer);
//Controller
return $this->render('MyBundle:RegistrationPages:register.html.twig',
array (
'errors' => $errors,
'form'=>$form
)
);
它顯示錯誤消息:
//Twig
{% if errors is defined %}
<h1>The Form has following errors</h1>
{% for error in errors %}
{{ error.message }}
{% endfor %}
{% endif %}
輸出:
測試所需
但:
{{ form_errors(form.address2) }}
沒有顯示任何東西。
你的意思是'{{form_errors(form.address2)}}'沒有顯示任何東西? – Mick
Yes..It顯示什麼:( –
return $this->render('MyBundle:RegistrationPages:register.html.twig', array ('errors' => $errors)); {% if errors is defined %}
輸出作爲測試所需要的,但The Form has following errors
{% for error in errors %} {{ error.message }} {% endfor %} {% endif %}{{ form_errors(form.fieldName) }}
顯示什麼 –