I solved this. I found the $router->match() method, which I am using against a cleaned up version of the $request->server->get('HTTP_REFERER'). This gives me the route parameters I need to generate my redirect route.
Here is the completed action: public function switchLangAction($_locale) { $newLang = ($_locale == "en") ? "fr" : "en"; $request = $this->get('request'); $router = $this->get('router'); $domain = $request->server->get('HTTP_HOST'); $referrer = $request->server->get('HTTP_REFERER'); // remove the protocol $referrer = preg_replace(';\b((ftp|https?)://)+?\b;', '', $referrer); // remove the domain $referrer = str_replace($domain, '', $referrer ); // remove the controller $referrer = str_replace($request->getBaseUrl(), '', $referrer); // remove the query string $referrer = preg_replace('/\?.*/', '', $referrer); // match the resulting cleaned up route $referrerParams = $router->match( $referrer ); // pluck the _route out of the params $referrerRoute = $referrerParams['_route']; unset($referrerParams['_route']); // switch the locale $referrerParams['_locale'] = $newLang; $response = new RedirectResponse( $this->generateUrl( $referrerRoute, $referrerParams )); return $response; } On May 9, 1:01 pm, Matt <matthieu.o.vac...@gmail.com> wrote: > Hi, > > This is how I did it: > > public function changeLocaleAction($locale) > { > if ($this->request->hasSession()) > $this->session->setLocale($locale); > > $referer = $this->request->server->get('HTTP_REFERER'); > if (!isset($referer)) > $referer = $this->generateUrl('index'); > > return new RedirectResponse($referer); > > } > > I'm not sure if it is the best to do it way but it works for me in my use > cases. > > Regards, > Matt -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en