I try not to find the "referrer" object for use in my controller. I expected that there would be an object similar to a query object with parameters defining _controller, _route and Arguments.
What I'm trying to do is a language switch that redirects the user to the same page in the new language . Something along the line:
public function switchLangAction($_locale)
{
$args = array();
$newLang = ($_locale == 'en') ? 'fr' : 'en';
$referrer = $this->get('referrer');
$referrerRoute = $referrer->parameters->get('_route');
$args = $referrer->parameters->get('args');
$args['_locale'] = $newLang;
$response = new RedirectResponse( $this->generateUrl(
$referrerRoute,
$args
));
return $response;
}
It is also possible that there is another way to do this - I know the rails, for example, there is a redirect_to: back method.
Any help would be greatly appreciated.
source
share