Zend元素装饰器

时间:2013-07-25 19:56:31

标签: php zend-framework decorator

我创建了一个元素提交:

   $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会出现致命错误?

1 个答案:

答案 0 :(得分:1)

我认为您需要改变:

$submit = $this->getElement('submit');

$submit = $this->getElement('button');

OR

$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()

相关问题