【问题标题】:how to set one decorator to more than one element in zend form如何以zend形式将一个装饰器设置为多个元素
【发布时间】:2011-05-02 11:54:47
【问题描述】:

在我的 zend 表单中,我为每个元素设置了 decarators ,而不是我可以设置适用于所有元素的单个装饰器。

目前..

    $code = new Zend_Form_Element_Text("mealplancode");
    $code->setLabel("Code :");
    $code->setDecorators(
                         array(
                              array('ViewHelper',
                                        array('helper' => 'formText')
                            ),
                            array('HtmlTag',
                                        array('tag' => 'div', 'class' => '')
                            ),
                            array('Label',
                                        array('class' => 'label')
                            ),
                         )
                      );

    $name = new Zend_Form_Element_Text("mealplanname");
    $name->setLabel("Name :");
    $name->setDecorators(
                         array(
                              array('ViewHelper',
                                        array('helper' => 'formText')
                            ),
                            array('HtmlTag',
                                        array('tag' => 'div', 'class' => '')
                            ),
                            array('Label',
                                        array('class' => 'label')
                            ),
                         )
                      );

我想在单个 setDecorator() 中将装饰器设置为 $name 和 $code 我可以这样做吗

【问题讨论】:

    标签: zend-framework zend-form


    【解决方案1】:

    在您的表单类中定义一个装饰器字段,以便能够将其应用于任何表单元素,例如:

    public $elementDecorators = array(
            'ViewHelper',
                array(array('data'=>'HtmlTag'), array('tag' => 'td')),
                array('Label', array('tag' => 'td')),
                array(array('row'=>'HtmlTag'),array('tag'=>'tr'))); 
    

    就像在您的代码中一样,您可以设置装饰器:

    $formElement->setDecorators($this->elementDecorators);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-25
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 1970-01-01
      • 2011-01-12
      相关资源
      最近更新 更多