dpw63348 2010-07-02 09:25
浏览 66

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条回答

  • dongpo7467 2010-07-02 10:10
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法