重定向到 Zend 框架中的上一页 [英] Redirect to previous page in zend framework

查看:29
本文介绍了重定向到 Zend 框架中的上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在登录页面中向我的登录表单操作(作为查询)添加重定向 URL,以便登录后可以访问他或她正在浏览的前一页.

I want to add a redirection URL to my login forms action (as a query) in login page, so after loging-in, one can visit the previous page he or she was surfing.

首先我想到了使用 Zend Session 并将每个页面的 url 保存在一个变量中.但我在文档中读到它有开销.那么,有没有更好的方法来做到这一点?或者有没有其他方法可以在没有开销的情况下使用 zend 会话?

First I thought about using Zend Session and save the url of each page in a variable. but I read in the documentation that it has overhead. So, is there a better way to do so? or is there an other way to use zend session with no overhead?

推荐答案

首先,您需要获取重定向的原始 url.你可以通过 Zend_Controller_Request 类通过:

First, you need to grab the original url for the redirection. You can do that by the Zend_Controller_Request class via:

$url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();

或简单地通过:

$url = $_SERVER['REQUEST_URI'];

然后,棘手的部分是通过用户请求传递它.我推荐使用 Zend_Session 库,尽管使用 POST 参数也是合法的:

Then, the tricky part is to pass it through the user request. I recommend to use the library Zend_Session, despite using a POST parameter is also legitimate:

$session = new Zend_Session_Namespace('Your-Namespace');
$session->redirect = $_SERVER['REQUEST_URI'];

请注意,我们保存的地址包括基本路径.要重定向控制器类中的客户端,请禁用选项 'prependBase' 以丢失基本路径插入:

Please note that the address we kept includes the base path. To redirect the client in the controller class, disable the option 'prependBase' to lose the base path insertion:

$this->_redirect($url, array('prependBase' => false));

这篇关于重定向到 Zend 框架中的上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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