Symfony 2 Forms entity Field Type grouping

后端 未结 2 1013
迷失自我
迷失自我 2020-12-06 02:56

I\'m rendering a form in Symfony2 with data_class mapped to Reservation entity, and this form has a entity field type, of class Service. The relati

相关标签:
2条回答
  • 2020-12-06 03:14

    I suppose the only way to do that is override rendering in the template. You should pass to your template entity MyBundle:Service and render it for example like this:

    {% for service in services %}    
        <b>{{ service.name }}</b><br>
        {% for option in service.options %}                    
            <label>
                <input type="checkbox" name="form_type_name[options][{{ option.id }}]" value="{{ option.id }}" {% if option in user.services.options %}checked="checked"{% endif %}>
                {{ option.name }}
            </label>
        {% endfor %}
    {% endfor %}
    
    0 讨论(0)
  • 2020-12-06 03:28

    This can be solved by using the group_by option:

    $builder->add('services','entity', array(
        'class' => 'MyBundle:Service',
        'group_by' => 'serviceType',
        'multiple' => true,
        'expanded'  => true
    ));
    
    0 讨论(0)
提交回复
热议问题