Symfony2 Render Form in the controller

How to visualize the form in the controller (not in the template)? I am looking for something like:

$form = $this->createForm(... $output = $form->render(); 

$ output will be the html for the form.

+4
source share
1 answer

A form is just an object, it does not know what its layout should be - what the template is for. If you use a controller that leaves the default controller, you can get the HTML code of the rendered template as follows: $html = $this->renderView('YourAppBundle:Blah:form.html.twig', array('form' => $form->createView() ) ); where this template contains the markup / rendering code of the form.

+8
source

Source: https://habr.com/ru/post/1443547/


All Articles