Zend framework Zend Form装饰问题

Zend framework Zend Form装饰问题,zend-framework,zend-form,decorator,Zend Framework,Zend Form,Decorator,我在Zend Form中遇到了一些与decorator相关的随机问题 首先, // THIS WORKS AND REMOVES THE DECORATORS $hidden = new Zend_Form_Element_Hidden('hiddenfield'); $hidden->setRequired(TRUE) ->removeDecorator('label') ->removeDecorator(

我在Zend Form中遇到了一些与decorator相关的随机问题

首先,

    // THIS WORKS AND REMOVES THE DECORATORS
    $hidden = new Zend_Form_Element_Hidden('hiddenfield');
    $hidden->setRequired(TRUE)
           ->removeDecorator('label')
           ->removeDecorator('HtmlTag')
           ->addErrorMessage('Please upload something');

    // BUT IT DOESNT WORK HERE - THE DECORATORS ARENT REMOVED
    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setLabel('Proceed to Part 2 of 2')
           ->removeDecorator('label')
           ->removeDecorator('HtmlTag')
           ->setAttrib('class', 'button fleft cta');
其次,创建如下的表单元素:

    $comments = new Zend_Form_Element_Textarea('comments');
    $comments->setLabel('Any comments')
             ->setRequired(FALSE);
    // THIS DOESNT WORK
    $this->addDisplayGroup(array('comments'),'comments');
    $comms = $this->getDisplayGroup('comments');
    $comms->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));
    $this->addElement($submit);
    $submit->setDecorators(array(
        array('ViewHelper'),
        array('Description'),
        array('HtmlTag')
    ));
并添加到如下显示组:

    $comments = new Zend_Form_Element_Textarea('comments');
    $comments->setLabel('Any comments')
             ->setRequired(FALSE);
    // THIS DOESNT WORK
    $this->addDisplayGroup(array('comments'),'comments');
    $comms = $this->getDisplayGroup('comments');
    $comms->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));
    $this->addElement($submit);
    $submit->setDecorators(array(
        array('ViewHelper'),
        array('Description'),
        array('HtmlTag')
    ));
未添加到字段集,但使用相同代码的自定义表单元素已添加到其自己的字段集:

    // THIS WORKS!
    $this->addDisplayGroup(array('custom'),'custom',array('legend'=>'Legend Here'));
    $swfupload = $this->getDisplayGroup('swfupload');
    $swfupload->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));

修复了包含“comments”元素的displayGroup的问题。显然,显示组不可能与其中包含的一个表单元素具有相同的名称。因此,解决办法是:

// THIS DOESNT WORK
$this->addDisplayGroup(array('comments'),'comments');
$comms = $this->getDisplayGroup('comments');
$comms->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Fieldset'
));

// THIS NOW WORKS
$this->addDisplayGroup(array('comments'),'commentsbox'); // change here
$comms = $this->getDisplayGroup('commentsbox'); // change here
$comms->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Fieldset'
));
并修复了另一个问题,即从之前的mass addement中删除submit,然后单独将其添加到表单中,手动删除装饰器,如下所示:

    $comments = new Zend_Form_Element_Textarea('comments');
    $comments->setLabel('Any comments')
             ->setRequired(FALSE);
    // THIS DOESNT WORK
    $this->addDisplayGroup(array('comments'),'comments');
    $comms = $this->getDisplayGroup('comments');
    $comms->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));
    $this->addElement($submit);
    $submit->setDecorators(array(
        array('ViewHelper'),
        array('Description'),
        array('HtmlTag')
    ));
我很想知道是否有更好的方法可以做到这一点