-1

我有一个具有以下操作的控制器:

public function addAction()
{
    //action for the comments submission
    $form = new Application_Form_Comment();
    $form->submit->setLabel('Comment');
    $this->view->form = $form;
    if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
        $comment = new Application_Model_DbTable_Comments();
        $comment->addComment($formData['comment'], $id);
            $this->_helper->redirector('index');
        } else {
            $form->populate($formData);
        }
    }

在我看来,如果我回显 $this->form; 表格不显示。

里克

4

1 回答 1

0

假设您试图将表单与任何特定控制器分开,您可以使用视图助手。自己写很容易

创建application/views/helpers/CommentForm.php将包含以下内容的文件:-

class Zend_View_Helper_CommentForm extends Zend_View_Helper_Abstract
{
    public function commentForm()
    {
        $form = new Application_Form_Comment();
        return $form;
    }
}

然后在您需要的任何视图中,只需执行以下操作:-

echo $this->commentForm();

这将呈现您的表单。

于 2012-04-18T22:47:01.447 回答