Language switcher redirecting to current page using symfony

What is the best way to make a language switch in symfony that redirects to the same page in the selected language? Jobeet is simply redirected to the main page.

+3
source share
1 answer

Something like this 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;
  }
}
+1
source

Source: https://habr.com/ru/post/1778592/


All Articles