0

也许有人知道。如何包装 Zend_Form_Element_Radio 包括整个无线电输入堆栈的标签(带有输入标签)。

public $radioDecorators = array(
    'ViewHelper',
    array('Description',array('tag'=>'div','class'=>'','placement' => 'prepend')),
    array('Errors',array('class'=>'error_message_show','placement' => 'prepend')),
    array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
    array('label', array('class'=>'label_text','placement' => 'prepend')),
    array(array('rows' => 'HtmlTag'), array('tag' => 'div', 'class' => 'radio')),
);


    $offer_type = new Zend_Form_Element_Radio('offer_type', array(
                'label' => 'Label I'd like to wrap with inputs',    //Label to wrap
                'required' => true,
                'description' => '',
                'decorators' => $this->radioDecorators,
                'multioptions' => array (
                    'standard' => 'standard',
                    'premium' => 'premium',
                ),
            ));
    $this->addElement($offer_type);

上面的例子没有解决我的问题,因为它只包含了几个输入标签。

4

1 回答 1

2

我想我知道你在追求什么,如果是这样,你很幸运,因为前几天我不得不这样做。

标准 ZF 多选项元素使用separator属性分隔每个“选项”(默认<br />为单选和换行符)。这对于<option>元素来说很好,但对于单选按钮的集合来说就很次要了。

解决方案是

  • 将 HtmlTag 装饰器添加到元素,包装内容
  • 设置分隔符关闭并重新打开 HtmlTag

例如,这是一个将输入集合包装在无序列表中的解决方案

$offer_type = new Zend_Form_Element_Radio('offer_type', array(
    'separator' => '</li><li>',
    'decorators' => array(
        'ViewHelper',
        array(array('liWrapper' => 'HtmlTag'), array('tag' => 'li')),
        array(array('ulWrapper' => 'HtmlTag'), array('tag' => 'ul')),
        // the rest
    )
));

另一种方法是编写自己的视图助手。创建自己的版本formRadio应该很容易。

于 2011-03-13T23:56:35.483 回答