【问题标题】:Wraping Labels in Zend_Form_Element_Radio在 Zend_Form_Element_Radio 中包装标签
【发布时间】:2011-03-13 16:45:58
【问题描述】:

也许有人知道。如何包装 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);

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

【问题讨论】:

  • 包裹是什么意思?你能提供一个你现在得到的html的例子,你想实现什么?

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


【解决方案1】:

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

标准的 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-09-24
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 2015-02-16
相关资源
最近更新 更多