mvc php中的公式验证

i have written validation class. now, is it ok to extend a form class from the validation class? or even extending the validation class from the request class?

i'm just not sure how to implement the registration process for a new user in a mvc. totally confuse.

Edit: i have found this zend tut here:

// 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;
      }
  }  

but i do not understand how in case of wrong inputs you can go back to the form page now with filled input fields

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

this just sets a value but does not redirect to registration.php. so how do i get to registration.php after this

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
}

1个回答



我不会扩展它。 它们有不同的“范围”(一个输入数据,另一个验证数据)...... </ p>

我建议依赖注入如果要强制验证,或者只是在必要时选择设置验证对象。 我之前做过两次。 </ p>
</ div>

展开原文

原文

I wouldn't extend it. They have different "scopes" (one inputs data, and the other validates data)...

I would suggest either Dependency Injection if you want to force validation, or simply the option of setting a validation object if necessary. I've done both before.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐