Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to previous page in zend framework

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.

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?

like image 900
Morteza Milani Avatar asked Aug 08 '09 16:08

Morteza Milani


1 Answers

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(); 

or simply by:

$url = $_SERVER['REQUEST_URI']; 

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']; 

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)); 
like image 99
Moshe Simantov Avatar answered Oct 12 '22 12:10

Moshe Simantov