Zend Framework:为Zend_Form元素设置默认装饰器的正确方法是什么

时间:2010-08-04 04:28:13

标签: zend-framework zend-form

我目前使用从Zend_Form扩展的类设置Zend_Form的默认装饰器...

class Application_Form_Abstract extends Zend_Form {
    ... 
    function loadDefaultDecorators() {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return $this;
        }

        // ... for elements
        $decorators = $this->_elementDecorators;
        if (empty($decorators)) {
            $this->setElementDecorators(array(
                'ViewHelper',
                'Errors',
                array('Description', array('tag' => 'p', 'escape' => false)),
                'Label',
                array('HtmlTag', array('tag' => 'p'))
            ));

但我很快意识到这一点,我无法定义像

这样的特定元素装饰器
$this->addElement('textarea', 'bio', array(
    'decorators' => array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'escape' => false)),
        'Label',
        array('HtmlTag', array('tag' => 'p')),
        new Application_Form_Decorator_WmdPreview,
     )
));

因为我们的自定义loadDefaultDecorators()功能会覆盖它们。我想知道是否有任何方法我可以为元素设置默认装饰器,如果他们没有设置装饰器

2 个答案:

答案 0 :(得分:0)

您可以通过添加对setDisableLoadDefaultDecorators()的调用来禁用'bio'元素的默认装饰器

$this->addElement('textarea', 'bio', array(
    'disableLoadDefaultDecorators' => true,
    'decorators' => array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'escape' => false)),
        'Label',
        array('HtmlTag', array('tag' => 'p')),
        new Application_Form_Decorator_WmdPreview,
     )
));

答案 1 :(得分:0)

另外,为了让您头疼,显示组不能与它们包含的任何元素具有相同的名称

相关问题