Zend framework Zend Framework:为Zend_表单元素设置默认装饰器的正确方法是什么
我目前使用从Zend framework Zend Framework:为Zend_表单元素设置默认装饰器的正确方法是什么,zend-framework,zend-form,Zend Framework,Zend Form,我目前使用从Zend_表单扩展的类为Zend_表单设置默认装饰器 class Application_Form_Abstract extends Zend_Form { ... function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return $this; } // ... for el
Zend_表单
扩展的类为Zend_表单
设置默认装饰器
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()
函数重写。我想知道是否有任何方法可以只在元素没有设置装饰器的情况下为元素设置默认装饰器您可以通过添加对setDisableLoadDefaultDecorators()的调用来禁用“bio”元素的默认装饰器
另外,为了省去您的麻烦,displaygroups不能与它们包含的任何元素具有相同的名称
$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,
)
));