Symfony2 实体字段类型(多对多形式)包裹在 <li>s 中 [英] Symfony2 entity field type (many-to-many form) wrapped in <li>s

查看:21
本文介绍了Symfony2 实体字段类型(多对多形式)包裹在 <li>s 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单 buildForm() 函数,看起来像这样:

I have a form buildForm() function that looks like this:

public function buildForm(FormBuilder $builder, array $options)
{   
    $builder->add('interestingSports', 'entity', array(
        'multiple' => true,
        'expanded' => true,
        'property' => 'name',
        'class'    => 'Foo\MyBundle\Entity\Sport',
    )); 
}

这很好用,除了表单只是弹出一堆没有

  • 或周围任何东西的复选框,我想要
  • s.

    This works fine, except the form just plops out a bunch of checkboxes with no <li>s or anything around them, and I want <li>s.

    Symfony 有没有办法让我将每个复选框放在

  • 中?

    Does Symfony have a way for me to put each checkbox in an <li>?

    推荐答案

    显示由

  • 标记包围的复选框的最佳和最简单的方法是 通过单独显示字段来自定义您的表单呈现

    The best and easiest way to display your checkboxes surrounded by <li> tags is to customize your form rendering by displaying fields individually,

    {# Any other form field #}
    {{ form_widget(form.otherField) }}
    {{ form_widget(form.otherField) }}
    {# ... #}
    {# Your checkboxes surrounded by <li> tags #}
    {% for field in form.interestingSports %}
       <li>
         {{ form_label(field) }}
         {{ form_widget(field) }}
       </li>
    {% endfor %}
    {# Render all fields that have not yet been rendered #}
    {{ form_rest(form) }}
    

    这篇关于Symfony2 实体字段类型(多对多形式)包裹在 &lt;li&gt;s 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆