在表单ZF2中设置DisplayGroup时出错

时间:2015-04-22 21:56:03

标签: php zend-framework2 zend-form

我尝试在表单中添加addDisplayGroup,但我收到以下错误:

  

"调用未定义的方法Application \ Form \ MyForm :: addDisplayGroup()"

这是我的表单代码:

namespace Application\Form;
use Zend\Form\Form;
class MyForm extends Form {


public function __construct()
{
    parent::__construct('Myform-form');
    $this->setAttribute('method', 'post');
    $this->addElements();
    $this->addInputFilter();
}

private function addElements() {
    $this->add(array(
        'type' => 'text',
        'name' => 'first_name',
        'attributes' => array(
            'id' => 'first_name'
        ),
        'options' => array(
            'label' => 'First Name: ',
        ),

    ));
    $this->add(array(
        'type' => 'text',
        'name' => 'last_name',
        'attributes' => array(
            'id' => 'last_name'
        ),
        'options' => array(
            'label' => 'Last Name: ',
        ),
    ));

    $this->addDisplayGroup(array('first_name', 'last_name'), 'information');

}
}