开发者

Zend Form - problem rendering individual elements

I have this simplified form:

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


        $this->form->addElement('text', 'firstName', array(
            'label' => 'First name: ',
        ));

and I want to render the element individually in my view page. Like so:

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

But I keep getting this error:

Fatal error: Uncaught except开发者_运维问答ion 'Zend_Form_Decorator_Exception' with message 'ViewHelper decorator cannot render without a registered view object'.

What am I doing wrong? I have pretty much followed the Zend Documentation on this page: http://framework.zend.com/manual/en/learning.form.decorators.individual.html

Sincerely, Why


You need to pass the form object after creating it in one of your controllers to your view script to render the form elements.

$this->view->form = $form;

And in your view script do something like

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜