Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply class to Symfony2 Form Label

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.

like image 894
jeremib Avatar asked Jul 25 '12 02:07

jeremib


1 Answers

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'} }) }} 
like image 181
Marko Jovanović Avatar answered Oct 29 '22 14:10

Marko Jovanović