Symfony 2 - several forms

Does anyone know how to display more forms on one page?

I have an ImportPath: id class of objects. description, path, local, and ImportPathForm corresponding to this object. What I want is somethnig as a table that has a small form in each row that can edit one Path in it.

I don’t know the final track count, so it must be dynamic in some kind of cycle. The requested form must be known from the path identifier (not yet implemented).

code: controller: public function importAction ($ message = "no message") {

$em = $this->getDoctrine()->getEntityManager();

$paths = $em->getRepository('WT2\BabuBundle\Entity\ImportPath')->findAll();

$forms=array();
foreach ($paths as $path) {
$form = $this->createForm(new ImportPathForm(), $path);
$forms[]=$form;
}

// $request = $this->getRequest();
// if ($request->getMethod() == 'POST') {
// $form->bindRequest($request);
// if ($form->isValid()) {
// /* ok */
// }
// }

return $this->render('WT2BabuBundle:Admin:import.html.twig', array('forms'=>$forms,'message'=>$message));
}

View (extract):

{% for key, form in forms %}
{{ key }}
<form action="{{ path('admin_import') }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<input type="submit" value="Ym2nit" />
</form>
{% endfor %}

EDIT>

I get it :)

decision

$forms=array();
foreach ($paths as $path) {
$form = $this->createForm(new ImportPathForm(), $path);
**$form = $form->createView();**
$forms[]=$form;
}
+3
source share
1 answer

I get it :)

decision

$forms=array();
foreach ($paths as $path) {
$form = $this->createForm(new ImportPathForm(), $path);
$form = $form->createView();
$forms[]=$form;
}
+5
source

All Articles