Apply class to Symfony2 Form Label

流过昼夜 提交于 2020-02-18 05:42:41

问题


I'm attempting to set the class on a class on a form label using php templates.

Here's my code:

<?php echo $view['form']->label($form['first_name'], 'First Name', array(
    'attr' => array('class' => 'control-label')
)) ?>

But here's my output:

<label class="required" for="form_first_name">First name</label>

I can find how to do it using twig, but not an example with PHP.


回答1:


I've got it...

<?php 
    echo $view['form']->label($form['first_name'], 'First Name', array(
            'label_attr' => array('class' => 'control-label'),
         )) 
?>

Apparently "attr" is "label_attr" for labels fields.

P.S. Corresponding twig code

{{ form_label(form.first_name, 'First Name', { 'label_attr': {'class': 'control-label'} }) }}


来源:https://stackoverflow.com/questions/11641727/apply-class-to-symfony2-form-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!