开发者

Language switcher, redirect to current page with symfony

开发者 https://www.devze.com 2023-01-29 10:37 出处:网络
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 d

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

精彩评论

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

关注公众号