Language switcher, redirect to current page with symfony
What is the best way to do 开发者_StackOverflowa language switcher in symfony that redirects to the same page in the chosen language? Jobeet simply redirects on the homepage.
Something like so should do the trick:
<?php
class myActions extends sfActions
{
public function executeLanguageSwitch(sfWebRequest $request)
{
$new_language = $request->getParameter('lang',false);
$this->forward404unless($new_language);
// You should probably insert stuff here check that the new culture passed in is valid
$this->getUser()->setCulture($new_language);
$this->redirect($request->getReferer());
return sfView::HEADER_ONLY;
}
}
This works for me:
<?php
class PageController extends Controller
{
public function changeLocaleAction(Request $request)
{
$locale = $request->get('_locale');
$this->get('session')->set('_locale', $locale);
$referer = $request->headers->get('referer');
return new RedirectResponse($referer);
}
}
精彩评论