在Zend_Form_Element_Radio中包装标签
问题描述:
也许有人知道。如何包装Zend_Form_Element_Radio,包括整个无线电输入堆栈的标签(带有输入标签)。在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);
上面的例子没的解决我的,因为它仅包装几个输入标签的。
答
我想我知道你在追求什么,如果是这样,你很幸运,因为我前几天不得不这样做。
标准ZF多选项元素使用separator
属性(默认为<br />
用于选择radio和newline)分隔每个“选项”。对于<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
版本应该很容易。
+0
正是我在寻找的东西。谢谢 :) – 2011-12-08 09:31:17
你是什么意思的包装?你能提供一个你现在得到的html的例子,你想达到什么目的? – Marcin 2011-03-13 23:20:19