我试图使用symfony2表单生成器向选项元素添加自定义属性即时通讯我不确定本机是否可行.如果不是我需要知道如何添加功能.
以下面的形式为例:
class FooForm extends AbstractType { public function buildForm(FormBuilderInterface $builder,array $options) { $builder->add('user','choice',array( 'choices' => array( 'designers'=>'designers','1'=>'mike','2'=>'carroll','developers'=>'developers','3'=>'chase','4'=>'brett','5'=>'jordan',) )); } }
然后在渲染时我需要它看起来像:
<select> <option value="" disabled="disabled">designers</option> <option value="1">mike</option> <option value="2">carroll</option> <option value="" disabled="disabled">developers</option> <option value="3">chase</option> <option value="4">brett</option> <option value="5">jordan</option> </select>
我所期待的将是这样的:
class FooForm extends AbstractType { public function buildForm(FormBuilderInterface $builder,array( 'choices' => array( 'designers'=>array( 'label'=>'designers','attr'=>arrry('disabled'=>'disabled') ),'developers'=>array( 'label'=>'developers',) )); } }
但那不起作用.所以对此的任何帮助将不胜感激.
它可以从2.7开始选择.看看
here.用choice_attr.