解析在zend Farmework下如何创立一个FORM表单(2)


<?php
class GuestbookController extends Zend_Controller_Action
{
    // snipping indexAction()...
    public function signAction()
    {
        $request = $this->getRequest();//获取接受到得信息
       // include_once("../application/forms/Guestbook.php");  手动加载类,只有不能自动载入时,才需要
        $form    = new Application_Form_Guestbook;//实例化这个方法

        if ($this->getRequest()->isPost()) {//如果是POST传递的结果
            if ($form->isValid($request->getPost())) {//判断传递是否有效
                $comment = new Application_Model_Guestbook($form->getValues());
                $mapper  = new Application_Model_GuestbookMapper();
                $mapper->save($comment);
                return $this->_helper->redirector('index');
            }
        }

        $this->view->form = $form;//将表单赋值给试图
    }
}


最后添加一个简单的sign视图文件即可:
地址:application/views/scripts/guestbook/sgin.php

复制代码 代码如下:


Please use the form below to sign our guestbook!
<?php
$this->form->setAction($this->url());
echo $this->form;


您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4b241fc11b12b51bb8f21fe36d2160c9.html