繁体   English   中英

在Symfony2应用程序中添加翻译功能时出现会话错误

[英]Session error when adding translation feature in Symfony2 application

在Symfony应用程序中添加翻译功能时出现错误:这是错误:

致命错误:在第41行上的C:\\ wamp \\ www \\ Symfony2 \\ src \\ MyApp \\ FilmothequeBundle \\ Controller \\ DefaultController.php中调用未定义的方法MyApp \\ FilmothequeBundle \\ Controller \\ DefaultController :: get()

第41行是:

$this->container->get('session')->setLocale($langue);

它在此控制器功能中:

public function choisirLangueAction($langue = null)
{
    if($langue != null)
    {
        // On enregistre la langue en session
        $this->container->get('session')->setLocale($langue);
    }
    // on tente de rediriger vers la page d'origine
    $url = $this->container->get('request')->headers->get('referer');
    if(empty($url)) {
        $url = $this->container->get('router')->generate('myapp_accueil');
    }
    return new RedirectResponse($url);
}

当我按下此链接时出现错误:

<a href="{{ path('myapp_choisir_langue', {'langue' : 'fr'}) }}">FR</a> 

这是匹配的路由文件的一部分:

myapp_choisir_langue:
   pattern: /choisir-langue/{langue}
   defaults: { _controller: MyAppFilmothequeBundle:Default:choisirLangue, _locale: fr}

我该如何实现?

您可以像symfony2 doc一样直接从控制器调用->get('service_name')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM