2012-02-07 6 views
0

私はsymfony2を使用しています。私はフォームを持っています、そして、私はそれをたくさんのテンプレートで何度も印刷したいのです。フォームを複数回印刷する。 Symfony2。 Twigテンプレート

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

$pruebas = $em->getRepository('UnetPBundle:prueba')->findAll(); 

$form = $this->createForm(new PruebaType(), $pruebas); 

return $this->render('UnetPBundle:Nomina:prueba.html.twig', array(

'form' => $form->createView(), 

'pruebas' => $pruebas      

)); 

そして、これは小枝のテンプレートの内容です:

これは私がコントローラーに持っているものです。

<form action="{{ path('UnetPBundle_prueba') }}" method="post" {{ form_enctype(form) }} class="sofla"> 

{{ form_errors(form) }} 

{% for prueba in pruebas %} 

{{ form_label(form.nombre, 'Nombre')}} 
{{ form_errors(form.nombre)}} 
{{ form_widget(form.nombre, {'attr':{'value':prueba.nombre}})}} 

{% endfor %} 

<input type="submit" value="Submit" /> 

{{ form_rest(form) }} 
</form> 

フィールドを1回だけ印刷しています。

答えて

2

CollectionType()から$ puebrasで初期化されたフォームを作成する必要があると思います。あなたのテンプレートにループは必要ありません。

+0

ありがとうございました!できます :) –

関連する問題