【问题标题】:Zend 1.12 change value of specific decorator in FormElementZend 1.12 更改 FormElement 中特定装饰器的值
【发布时间】:2013-06-23 02:24:34
【问题描述】:

我正在使用表格格式呈现一个非常简单的表单。我首先添加元素,然后使用以下内容设置它们的基本装饰器:

$this->setElementDecorators(array(
        'Viewhelper',
        array(array('data'=>'HtmlTag'),array('tag'=>'td')),
        'Label',
        array(array('labelCell'=>'HtmlTag'),array('tag'=>'td', 'align'=>'right')),
        array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
    ));

之后,我操纵任何一组元素(根据需要)来设置不同的外观,例如:将元素组合在一行中。为此,执行以下操作:

$this->getElement($elementName)->setDecorators(array(
        'Viewhelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'colspan' => $colspan)),
        'Label',
        array(array('labelCell' => 'HtmlTag'), array('tag' => 'td', 'align' => 'right')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

如你所见,我必须再次将 setDecorators() 添加所有(默认),所以我可以更改 'data' 装饰器并添加属性 "colspan"

我的问题是:是否可以访问和更改单个装饰器而无需不必设置元素之前的所有装饰器?

【问题讨论】:

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


    【解决方案1】:

    你应该可以打电话了:

    $viewHelperDecorator = $this->getElement($elementName)->getDecorator('ViewHelper');
    

    然后,这就像任何其他装饰器(它是一个装饰器抽象) - 所以你可以调用

    $viewHelperDecorator->setOption();
    

    并设置您想要的更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-25
      • 2011-01-10
      • 2013-10-25
      • 1970-01-01
      • 2011-01-09
      • 2015-08-19
      • 2010-12-10
      • 2011-01-20
      相关资源
      最近更新 更多