0

我正在尝试为渲染的收音机添加属性

$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' 的引用

我在网上找不到任何问题

4

2 回答 2

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>
于 2013-05-20T02:41:17.953 回答
0

你的树枝代码是什么样子的?您使用哪种表单模板?

您使用自定义表单模板是因为 <div class="control-group"> <label class="control-label required">Myradios</label> <div class="controls"> 绝对不是标准的 Symfony!

于 2013-06-17T15:23:58.477 回答