【发布时间】:2010-07-02 09:25:57
【问题描述】:
我已经编写了验证类。现在,可以从验证类扩展一个表单类吗?甚至从请求类扩展验证类?
我只是不确定如何在 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
}
【问题讨论】:
标签: php model-view-controller validation forms registration