A: 

Zend not have fuction for this. But simple way, save url in session and use it here

GremniX
I dont want to store the url in a session, there must be another way?
bluedaniel
See Gordon answer, it's one of another way. But if you want redirect more than one page back, you need store url in session
GremniX
+3  A: 

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.

Gordon
Ive just created that function in the controller itself, thanks!
bluedaniel
@bluedaniel you're welcome. as long as you only need it in one action, it's fine inside the controller. If you need it in multiple controllers, a helper is the better way because you don't need to duplicate code.
Gordon
yeah I understand that, I'll probably end up moving it a bit later but its fine for now. Being new to Zend, it seems at times Zend makes easy tasks much harder than they ought to be.
bluedaniel
A: 

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.

Peter M
A: 

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. 
Boris K