How to set a class attribute to a Symfony2 form input

前端 未结 8 1923
生来不讨喜
生来不讨喜 2020-11-29 23:27

How can I set the HTML class attribute to a form using the FormBuilder in Symfony2 ?

S

8条回答
  •  余生分开走
    2020-11-30 00:06

    You can add it in the options of your form class:

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\MyEntity',
            'attr' => array(
                'class' => 'form-horizontal'
            )
        ));
    }
    

提交回复
热议问题