加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony 2实体字段属性

发布时间:2020-12-13 22:53:12 所属栏目:PHP教程 来源:网络整理
导读:我的形式是实体领域.此字段如下所示: -add('user','entity',array( 'class' = 'ElearningSiteBundleEntityUser','property' = 'name','multiple' = true,'expanded' = true,'required' = true,'label' = 'U?ytkownicy ','attr' = array('class' = 'userF
我的形式是实体领域.此字段如下所示:

->add('user','entity',array(
                                'class' => 'ElearningSiteBundleEntityUser','property' => 'name','multiple' => true,'expanded' => true,'required' => true,'label' => 'U?ytkownicy ','attr' => array('class' => 'userFiledCollection'),// this not working. It set class to parent div. I want to have this class in checkboxes.
                                'query_builder' =>function(EntityRepository $er) {
                                                     return $er
                                                        ->createQueryBuilder('u')
                                                        ->where('u.isActive = 1');
                                                      },)
                    )

我想要做的就是为这个字段呈现的所有复选框设置一个类属性.我怎样才能做到这一点?

解决方法

没有内置解决方案.见 this issue.

可能的解决方案 – 使用Form theming:

{% form_theme form _self %}

{% block checkbox_widget %}
    {% spaceless %}
        {% set attr = attr|merge({'class': 'userFiledCollection'}) %}
        <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
    {% endspaceless %}
{% endblock checkbox_widget %}

{% block body %}
    {{ form(form) }}
{% endblock %}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读