php - How do I render validation errors in controller through twig template -
how render validation errors in controller through twig template. not able access validation errors in controller.
i found way
$validator = $this->get('validator'); $errors = $validator->validate($entity); $content = $this->renderview('yourbundle:yourentity:template.html.twig',array('errors'=>$errors)); {% if errors %} {% error in errors %} <li>{{ error.message }}</li> {% endfor %} {% endif %}
how field name has error out here
$validator = $this->get('validator'); $errors = $validator->validate($entity); $content = $this->renderview('yourbundle:yourentity:template.html.twig',array('errors'=>$errors)); {% if errors %} {% error in errors %} <li>{{ error.message }}</li> <li>{{ error.propertypath }}</li> {% endfor %} {% endif %}
Comments
Post a Comment