mvc-php中的公式验证

mvc-php中的公式验证,php,model-view-controller,validation,forms,registration,Php,Model View Controller,Validation,Forms,Registration,我在课堂上写过验证。现在,可以从验证类扩展表单类了吗?或者甚至从请求类扩展验证类 我只是不知道如何在mvc中实现新用户的注册过程。完全弄糊涂了 编辑:我在这里找到了这个zend tut: // application/controllers/GuestbookController.php class GuestbookController extends Zend_Controller_Action { // snipping indexAction()...

我在课堂上写过验证。现在,可以从验证类扩展表单类了吗?或者甚至从请求类扩展验证类

我只是不知道如何在mvc中实现新用户的注册过程。完全弄糊涂了

编辑:我在这里找到了这个zend tut:

// application/controllers/GuestbookController.php
  class GuestbookController extends Zend_Controller_Action

  {
      // snipping indexAction()...

      public function signAction()
      {
          $request = $this->getRequest();
          $form    = new Application_Form_Guestbook();

          if ($this->getRequest()->isPost()) {
              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;
      }
  }  
但我不明白,如果输入错误,您现在如何返回表单页面,填写输入字段

$this->view->form = $form;
这只是设置一个值,但不会重定向到registration.php。那么,在这之后我如何访问registration.php呢

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');
}
else {
    // ... do redirect to registration.php and fill input fields with set $_POST
}

我不会延长的。它们有不同的“作用域”(一个输入数据,另一个验证数据)

我建议您要么强制验证,要么在必要时设置验证对象。我以前都做过