多次打印表格。 Symfony2.树枝模板
我用的是symfony2。我有一个表格,我想在树枝模板上多次打印它。
这是我在控制器中的内容:
$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>
它只打印该字段一次。
I'm using symfony2. I have a form, and I want to print it a lot of times on a twig template.
This is what I have in the Controller:
$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
));
And this is the content of twig template.
<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>
It's printing the field just once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要从使用 $puebras 初始化的
CollectionType()
创建一个表单。模板中不需要循环。I think you'll need to create a form from a
CollectionType()
initialized with $puebras. There will be no need for a loop in your template.尝试将
$puebras
定义为 实体字段类型< /a>.Try to define
$puebras
as entity field type.