Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend Form-呈现单个元素时出现问题_Php_Zend Framework_Zend Form - Fatal编程技术网

Php Zend Form-呈现单个元素时出现问题

Php Zend Form-呈现单个元素时出现问题,php,zend-framework,zend-form,Php,Zend Framework,Zend Form,我有一个简化的表格: $this->form = new \Zend_Form(); $this->form->setAction($request->currentPath()); $this->form->setMethod('post'); $this->form->addElement('text', 'firstName', array( 'lab

我有一个简化的表格:

        $this->form = new \Zend_Form();
        $this->form->setAction($request->currentPath());
        $this->form->setMethod('post');


        $this->form->addElement('text', 'firstName', array(
            'label' => 'First name: ',
        ));
我想在我的视图页面中单独呈现元素。像这样:

        <?php echo $form->firstName->renderViewHelper() ?>

但我一直在犯这样的错误:

致命错误:未捕获异常“Zend\u Form\u Decorator\u exception”,消息为“ViewHelper Decorator无法在没有注册视图对象的情况下渲染”

我做错了什么?我基本上遵循了本页上的Zend文档:

真诚地,
为什么

在一个控制器中创建表单对象后,需要将其传递给视图脚本以呈现表单元素

$this->view->form = $form;
在您的视图中,脚本执行以下操作

echo $this->form->firstName->renderViewHelper();