【发布时间】:2009-12-07 11:28:13
【问题描述】:
我在使用 Zend_Form 摆脱默认的装饰器集时遇到了麻烦。
我正在尝试扩展 Zend_Form 以实现不同的装饰器样式。
class CRM_Form extends Zend_Form
{
public function init()
{
$this->setDisableLoadDefaultDecorators(true);
$this->addDecorator('FormElements')
->addDecorator('Form');
$this->setElementDecorators(array(
'ViewHelper',
'Label',
'Errors',
new Zend_Form_Decorator_HtmlTag(array('tag' => 'p'))
));
}
}
当我尝试像这样使用这个类时:
$form = new CRM_Form();
$form->setAction('/')->setMethod('post');
$id = $form->createElement('text','id')->setLabel('ID:');
$form->addElement($id);
使用旧的装饰器(定义列表)而不是我的段落样式。
如果我在 CRM_Form 类的 init() 方法中添加元素(),它们会使用我设置的样式。
如何强制使用该类创建的所有元素使用我的默认样式?
【问题讨论】:
标签: php zend-framework zend-form