Controller 中的一个 Action 从数据库中生成下一个 ID,并将其显示在屏幕上作为引用。如果用户单击刷新,我如何防止再次调用该操作。
最佳答案
Zend Framework 的 post-redirect-get 模式通常涉及将表单的操作留空(因此它发布到自身),然后在您不想再次显示表单时重定向(因此在成功时)。
public function newAction() {
$form = new Form_Foo();
if($this->_request->isPost()) {
if($form->isValid($this->_request->getPost()) {
//save or whatever
return $this->_redirect('path/to/success');
}
// else fall through
}
$this->view->form = $form;
}
关于php - 防止在 Zend 框架中重新提交表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1278688/