Let's assume you have a page the user wants to access, but it requires a login first or some other action. Most web pages just redirect you to the login and then you have to go find the page you wanted to see.
Step 1: open a page that has some prerequisite
Step 2: you get an ugly error
The page that showed you this error saves the URL you really wanted to visit.
For example the code in a static function would be :
$lastPg = new Zend_Session_Namespace('ditta_redirect'); $lastPg->url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(); $lastPg->setExpirationHops(2); self::$flashMessenger->addMessage(array('alert', self::$translate->translate('per questa operazione devi prima selezionare una ditta') . "\n")); self::$redirector->gotoSimple("index", "index");
The user then logs in (or chooses something)
After you process the page, you load the saved url and redirect the user to the page he initially wanted to see.
This is the code
$namespace = new Zend_Session_Namespace('ditta_redirect'); $redirect_after_login_url = $namespace->url; if ($redirect_after_login_url == "/user/login" || $redirect_after_login_url == "/user/logout") $redirect_after_login_url = "/index/index"; if (!empty($redirect_after_login_url)) $this->_helper->redirector->gotoUrl($redirect_after_login_url);
Tadaaa you finally got to the inital requested page.
However note a feature. If the user doesn't choose something, but clicks on any other link,
then the saved url will be deleted since he will go beyond 2 hops(= 2 page redirects). In this way, if he chooses that something in the future, he will not be redirected to the saved url(since there will be no redirected URL), but will remain on the same page.