如何通过 Zend 中的控制器重定向页面 [英] how to redirect a page through controller in zend

查看:48
本文介绍了如何通过 Zend 中的控制器重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击提交按钮时,我希望页面重定向到下一页?

header('位置:/pdp/policy-info.phtml');

我在控制器代码中写了上面的代码,但我无法重定向到上面的页面.它停留在同一页面上.文件名在视图中称为 policy-info.phtml.

此外,一旦我重定向,我是否可以通过 $_POST 访问我的表单值?或者有没有其他选择.

解决方案

好吧,我觉得你可能漏掉了几个概念:

  • 您永远不会重定向到 phtml 文件.(除非您编写了一些自定义的重写/路由规则)Zend 使用 MVC 架构,URL 以这种方式存在:

    /module/controller/view/key1/value1/keyx/valuex/

    通常,zend 网址不会以文件扩展名终止.此外,您永远不会直接从浏览器调用视图文件.

  • 在您的表单标签中,您可以使用 action 属性指定表单提交到的位置.对于您的网址,我假设 pdp 控制器和政策信息操作

<前>动作="/pdp/policy-info/"

  • 如果您想在使用控制器提交表单后重定向,您可以使用:
<前>$this->_redirect('/pdp/policy-info/');# 也许你想执行一些代码然后执行# 另一个控制器中的附加代码,无需重新引导$this->_forward('policy-info', 'pdp');

http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.utilmethods

  • 如果您重定向,您将无法访问您的 POST,除非您将这些值保存在其他地方(例如在您的会话中).如果您转发,我相信这些值在第二个操作中仍然可用.

When I click on a submit button i want the page to redirect to the following page?

header('Location: /pdp/policy-info.phtml');

I wrote the above code in the controller code but I am not able to redirect to the above page. it stays on the same page. the filename is called policy-info.phtml in the view.

Also once I redirect, would I be able access my form values through $_POST? Or is there an alternative.

解决方案

ok it sounds to me like you may be missing a few concepts:

  • You will never redirect to a phtml file. (unless you have written some custom rewrite/route rules) Zend uses the MVC architecture, urls exist in this fashion:

    /module/controller/view/key1/value1/keyx/valuex/

    generally zend urls don't terminate with file extensions. Also you will never directly call a view file from your browser.

  • In your form tag, you specify where the form submits to with the action attribute. For your url i'm assuming the pdp controller and policy-info action

    action="/pdp/policy-info/"

  • If you want to redirect after a form submit from with your controller you would use:

    $this->_redirect('/pdp/policy-info/'); 

    # maybe you want to execute some code and then execute 
    # additional code in another controller without re-bootstrapping
    $this->_forward('policy-info', 'pdp');

http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.utilmethods

  • If you redirect you will not have access to your POST unless you saved those values elsewhere (like in your session). If you forward, I believe the values will still be available in the second action.

这篇关于如何通过 Zend 中的控制器重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆