我正在尝试为我渲染的无线电添加属性
$builder
->add('myRadios', 'choice', array(
'choices' => array(
'one' => 'uno',
'two' => 'due'),
'multiple' => false,
'attr' => array('class' => 'testClass'),
'expanded' => true
输出是:
<div class="control-group">
<label class="control-label required">Myradios</label>
<div class="controls">
<label for="form_one_0" class="required radio">
<input type="radio" id="form_one_0" name="form[one]" required="required" value="uno" />
<span>Uno</span>
</label>
<label for="form_two_1" class="required radio">
<input type="radio" id="form_two_1" name="form[two]" required="required" value="due" />
<span>Due</span>
</label>
</div>
</div>
没有引用class ='testClass'
我在网上找不到任何问题
答案 0 :(得分:1)
尝试这种方式亚当,
$form = $app['form.factory']->createBuilder('form')
->add('myRadios', 'choice', array(
'choices' => array(
'one' => 'uno',
'two' => 'due'),
'multiple' => false,
'expanded' => true,
'attr' => array('class' => 'testClass'),
))
->getForm();
它有效:
<div id="form_myRadios" class="testClass">
<input type="radio" id="form_myRadios_0" name="form[myRadios]" required="required" value="one">
<label for="form_myRadios_0" class="required">uno</label>
<input type="radio" id="form_myRadios_1" name="form[myRadios]" required="required" value="two">
<label for="form_myRadios_1" class="required">due</label>
</div>
答案 1 :(得分:0)
你的枝条代码怎么样?您使用哪种表单模板?
您使用自定义表单模板,因为
<div class="control-group">
<label class="control-label required">Myradios</label>
<div class="controls">
绝对不是标准的Symfony!