所以我有这两个代码:
我的PHP代码
$builder
->setMethod("GET")
->add(
"type"
, "choice"
, array(
"choices" => array("student"=>"Student ID", "hr"=>"HR number")
, "expanded" => true
, "label_attr" => array(
"class" => "myclasshere"
)
, "multiple" => false
, "required" => false
)
我的小树枝模板:
{{ form_label(form.type[0]) }}
我的问题是没有类被应用到标签上。
我也试过:
{{ form_label(form.type[0], {"label_attr":{"class":"myclasshere"}}) }}
这是一个错误。
有什么想法吗?我的选择是自己写标签标签,而不是使用Twig。
感谢
第二个参数应该是标签文本,或者为null。
{{ form_label(form.type[0], null, {"label_attr":{"class":"myclasshere"}}) }}
类是标签标签的一个属性,所以在Twig中,它应该写在"attr"数组中,如下所示:
{{ form_label(form.type[0], {"attr":{"class":"myclasshere"}}) }}