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