在symfony中使用所选语言重定向到同一页面的语言切换器的最佳方法是什么? Jobeet只是在主页上重定向。
答案 0 :(得分:1)
这样的事情应该可以解决问题:
<?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 :(得分:0)
这对我有用:
<?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);
}
}