[英]How do I render validation errors in controller through twig template
如何通過樹枝模板在控制器中呈現驗證錯誤。 我無法訪問控制器中的驗證錯誤。
我找到了一種方法來做到這一點
$validator = $this->get('validator');
$errors = $validator->validate($entity);
$content = $this->renderView('YourBundle:YourEntity:template.html.twig',array('errors'=>$errors));
{% if errors %}
{% for error in errors %}
<li>{{ error.message }}</li>
{% endfor %}
{% endif %}
如何在此處獲取出現錯誤的字段名稱
$validator = $this->get('validator');
$errors = $validator->validate($entity);
$content = $this->renderView('YourBundle:YourEntity:template.html.twig',array('errors'=>$errors));
{% if errors %}
{% for error in errors %}
<li>{{ error.message }}</li>
<li>{{ error.propertypath }}</li>
{% endfor %}
{% endif %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.