多次打印表格。 Symfony2.树枝模板

发布于 2025-01-03 17:58:38 字数 894 浏览 4 评论 0原文

我用的是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九局 2025-01-10 17:58:38

我认为您需要从使用 $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.

小耗子 2025-01-10 17:58:38

尝试将 $puebras 定义为 实体字段类型< /a>.

Try to define $puebras as entity field type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文