开发者

Zend Form - problem rendering individual elements

开发者 https://www.devze.com 2023-03-03 13:20 出处:网络
I have this simplified form: $this->form = new \\Zend_Form(); $this->form->setAction($request->currentPath());

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

精彩评论

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

关注公众号