Zend not have fuction for this. But simple way, save url in session and use it here
There is no built-in way to do this afaik. You want to redirect back to the referer, which may or may not be stored in $_SERVER['HTTP_REFERER']
.
The best approach I can think of is writing a Zend_Controller_Action_Helper
with a method signature like this
// Returns the referer from $_SERVER array or $fallback if referer is empty
public function getReferer($fallback);
// proxy to getReferer()
public function direct($fallback);
Then you could use
public function switchLanguageAction
{
// ... insert code to switch the language for this user ...
$this->_redirect( $this->_helper->referer('/fallback/to/url') );
}
As an alternative, you could use a custom redirect helper that can achieve the same in one go.
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.redirector.basicusage mentions $this->_redirector->redirectAndExit();
I think that maybe you are looking at this from the wrong angle. A controller is fired after the routing has completed. From what I am seeing you really want to change the language and then route to the controller. This would be achieved via customizing the front controller and tapping in to one of the events there.
Another simple way to grab/set the referer is via adding a param to your frontController in your Bootstrap code:
$frontController = Zend_Controller_Front::getInstance();
$frontController->setParam('referer', $_SERVER['HTTP_REFERER']);
and then grab the referer from your controller like so:
$referer = $this->getInvokeArg('referer');
From the Zend docs for Zend_Controller_Front:
7.3.4. Front Controller Parameters
In the introduction, we indicated that the front controller also acts as a registry for the various controller components. It does so through a family of "param" methods. These methods allow you to register arbitrary data – objects and variables – with the front controller to be retrieved at any time in the dispatch chain. These values are passed on to the router, dispatcher, and action controllers.