symfony改变attribut'for'form_label

时间:2016-02-08 11:28:03

标签: php forms symfony twig widget

我在谷歌搜索但我没有找到如何更改(夸大)form_label中的'for'attribut。

{{ form_widget(form.star,{'id':'rating-input-1-5','attr':{'class':'rating-input'}}) }}
                                    {{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-5'}}) }}
                                    {{ form_widget(form.star,{'id':'rating-input-1-4','attr':{'class':'rating-input'}}) }}
                                    {{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-4'}}) }}
                                    {{ form_widget(form.star,{'id':'rating-input-1-3','attr':{'class':'rating-input'}}) }}
                                    {{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-3'}}) }}
                                    {{ form_widget(form.star,{'id':'rating-input-1-2','attr':{'class':'rating-input'}}) }}
                                    {{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-2'}}) }}
                                    {{ form_widget(form.star,{'id':'rating-input-1-1','attr':{'class':'rating-input'}}) }}
                                    {{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-1'}}) }}

我想在form_widget的id上使用form_label点。

有可能吗?

感谢您的回答

1 个答案:

答案 0 :(得分:1)

尝试将form_label调用更改为

{{ form_label(form.star,null,{'id':'rating-input-1-5', 'label_attr':{'class':'rating-star'}}) }}