【问题标题】:Session error when adding translation feature in Symfony2 application在 Symfony2 应用程序中添加翻译功能时出现会话错误
【发布时间】:2012-11-26 16:22:40
【问题描述】:

在我的 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}

我怎样才能做到这一点?

【问题讨论】:

    标签: php session symfony translation


    【解决方案1】:

    您可以像在symfony2 doc 中一样直接从您的控制器调用-&gt;get('service_name')

    【讨论】:

    • 您不应在答案中添加签名。
    猜你喜欢
    • 2021-12-06
    • 2018-07-29
    • 1970-01-01
    • 2021-11-19
    • 2016-11-21
    • 2015-10-07
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多