【发布时间】:2011-01-10 01:31:34
【问题描述】:
我在 Zend Form 中遇到了一些与装饰器相关的随机问题。
首先,
// 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'
));
未添加到 Fieldset,但使用相同代码的自定义表单元素已添加到其自己的字段集:
// 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'
));
【问题讨论】:
标签: zend-framework zend-form decorator