<?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;
您可能感兴趣的文章: