【发布时间】:2012-02-06 22:09:32
【问题描述】:
当我点击提交按钮时,我希望页面重定向到下一个页面?
header('Location: /pdp/policy-info.phtml');
我在控制器代码中编写了上面的代码,但我无法重定向到上面的页面。它保持在同一页面上。 该文件名在视图中称为 policy-info.phtml。
此外,一旦我重定向,我可以通过 $_POST 访问我的表单值吗? 或者有其他选择吗?
【问题讨论】:
当我点击提交按钮时,我希望页面重定向到下一个页面?
header('Location: /pdp/policy-info.phtml');
我在控制器代码中编写了上面的代码,但我无法重定向到上面的页面。它保持在同一页面上。 该文件名在视图中称为 policy-info.phtml。
此外,一旦我重定向,我可以通过 $_POST 访问我的表单值吗? 或者有其他选择吗?
【问题讨论】:
好吧,在我看来,您可能遗漏了一些概念:
您永远不会重定向到 phtml 文件。 (除非您编写了一些自定义的重写/路由规则) Zend 使用 MVC 架构,url 以这种方式存在:
/module/controller/view/key1/value1/keyx/valuex/通常 zend url 不会以文件扩展名终止。此外,您永远不会直接从浏览器调用视图文件。
在您的表单标签中,您可以使用 action 属性指定表单提交到的位置。对于您的 url,我假设 pdp 控制器和策略信息操作
http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.utilmethods
【讨论】:
实际上可能有几种方法可以做你想做的事。我还没有尝试过第一种方法,但它应该可以工作。
如果 isPost() 从你的控制器/动作中渲染一个新的 veiw 脚本:
public function myAction(){
$form = My_Form();
$this->view->form = $form;
//if form is posted and submit = Submit
if ($this_request->isPost() && $this_request->getPost()->submit == 'Submit') {
if ($form->isValid($this->_request->getPost()) {
//this is where you want to capture form data
$data = $form->getValues();
//render a new viewscript or _forward to a new action and perform your processing there.
$this->render('path to phtml file');
//if user needs to press a button to accept submit = accept
...do some more stuff...
}
}
}
我认为这个或一些变化会起作用。
注意:我不认为 _forward 会重置请求对象,因此您的 $_POST 数据不应该受到影响。
此外,如果此策略信息不需要用户的额外输入并且只是提供信息,您可以轻松地将 _forward('action') 设置为空白操作,路由器将显示视图脚本。
【讨论】: