开发者

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜