【问题标题】:Zend Form - problem rendering individual elementsZend Form - 渲染单个元素的问题
【发布时间】:2011-08-21 01:16:04
【问题描述】:

我有这个简化的形式:

        $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_Form_Decorator_Exception”与消息“ViewHelper 装饰器无法在没有注册的视图对象的情况下呈现”。

我做错了什么?我非常关注此页面上的 Zend 文档: http://framework.zend.com/manual/en/learning.form.decorators.individual.html

真诚地, 为什么

【问题讨论】:

    标签: php zend-framework zend-form


    【解决方案1】:

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

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

    在你的视图脚本中做类似的事情

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 2011-04-04
      • 2013-10-19
      相关资源
      最近更新 更多