我创建了一个元素submit:
$this->addElement('submit', 'button', array(
'ignore' => true,
'label' => 'Update',
'class' => 'btn blue',
));
现在尝试为这个元素设置装饰器:
$submit = $this->getElement('submit');
$submit->setDecorators(array(
array('ViewHelper'),
array('Description'),
array('HtmlTag', array('tag' => 'div', 'class'=>'submit-group')),
));
我的代码出现了问题,因为我在没有对象的情况下调用成员函数setDecorators
时出现了致命错误?
我认为您要么需要更改:
$submit = $this->getElement('submit');
至
$submit = $this->getElement('button');
或
$this->addElement('submit', 'button', array(
'ignore' => true,
'label' => 'Update',
'class' => 'btn blue',
));
至
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Update',
'class' => 'btn blue',
));
addElement的第一个参数似乎是element type
,第二个参数是element id
。而不是相反。
而且,getElement需要接受element id
才能工作,而不是element type
有关详细信息,请参阅此处:http://framework.zend.com/apidoc/1.10/_Form.html#Zend_Form::addElement()http://framework.zend.com/apidoc/1.10/_Form.html#Zend_Form::getElement()