为无线电元素设置Zend装饰

时间:2013-04-29 16:50:56

标签: zend-framework zend-form zend-form-element zend-decorators

我需要设置要打印的装饰:

<input type="radio" id="option1" name="option" value="foo">
<label for="option1"></label>
<label>Option 1</label>

使用Zend_Form_Element_Radio。

我试过了:

$pass = new Zend_Form_Element_Radio('options');
    $pass->setLabel('Bloquear:')
            ->setRequired(true)
            ->addMultiOptions(array(
                'option1' => '<label for="options-1"></label><label>Option 1</label>',
                'option2' => '<label for="options-2"></label><label>Option 2</label>'));
    return $pass;

但它打印的标签不是HTML。建议?

1 个答案:

答案 0 :(得分:0)

您必须定义自定义装饰器,如下例所示,以管理<ul><li>

在ul和li的基础上应用css会很容易。看看那个

$this->addElement('radio', 'Bloquear', array(
    'decorators' => array(
        'ViewHelper',
        array(array('AddTheLi' => 'HtmlTag'), array('tag' => 'li')),
        array(array('AddTheUl' => 'HtmlTag'), array('tag' => 'ul')),
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),

    // specifying the "div" tag to wrap your <label> elements is not strictly 

    // necessary, but it produces valid XHTML if your form elements are wrapped

    //  in block-level tags like "<li>" (see next comment)
    array('Label', array('tag' => 'div')),

    // uncomment the following if all of your form elements are wrapped in "<li>"
    //array('HtmlTag', array('tag' => 'li')),
),
'disableLoadDefaultDecorators' => true,
'label' => 'Bloquear',
'separator' => '</li><li>',
'attribs' => array(
    'options' => array(
        'foo' => 'Option 1', 
        'bar' => 'Option 2', 
        'baz' => 'Option 3'
    ),
),

));

如果我能为您提供更多帮助,请告诉我。