您现在的位置: 华盟网 >> 编程 >> PHP编程 >> 正文

Symfony2: Sticky language does not stick always

2015/12/8 作者:不祥 来源: 互联网
导读 Symfony2: Sticky language does not stick always,Ihaveweirdproblem,thatneverhappenedbefore.Thestickyl

I have weird problem, that never happened before. The sticky language does not working always.

Its starts working for a while when doing these steps:

go to dev environment click to profiler go back to dev enviroment switch language go to production enviroment

Viola, the sticky language now works.

I have tried several ways, googled, stackoverflowed, used own brain to customize language handling in tons of different ways. For example set a custom session variable then based on its value I have tried to set request language and also language to session. But as soon as page loads, this native session variable is lost including request parameters.

Here is my current LocateListener witch works as described above:

class LocateListener implements EventSubscriberInterface { private $defaultLocale; public function __construct($defaultLocale = 'sk') { $this->defaultLocale = $defaultLocale; } public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->hasPreviousSession()) { return; } // try to see if the locale has been set as a _locale routing parameter if ($locale = $request->attributes->get('_locale')) { $request->getSession()->set('_locale', $locale); // echo "locale changed"; } else { // if no explicit locale has been set on this request, use one from the session $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale)); $request->getSession()->set('_last_locale_url', $actual_link = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); } } public static function getSubscribedEvents() { return array( // must be registered before the default Locale listener KernelEvents::REQUEST => array(array('onKernelRequest', 17)), ); } }

The controller action that handles language switch:

public function switchlangAction(Request $req) { return $this->redirect($req->headers->get("referer")); }

The routing:

erik_app_switchlang: path: /locale/{_locale} defaults: { _controller: ErikAppBundle:Default:switchlang } requirements: _locale: sk|en

The session configuration:

session: cookie_domain: netlime.tk cookie_lifetime: 3600 cookie_httponly: false

The way how locale listener is registered

app.locale_listener: class: Erik\AppBundle\Service\LocateListener arguments: ["%kernel.default_locale%"] tags: - { name: kernel.event_subscriber, priority: 17 }

The website I am talking about is https://www.netlime.tk app_dev is allowed, you can try it if required. http://tvarplast.sk website runs on same sticky language code and there it works.

Netlime runs on custom vps on digital ocean with comodo certificate.

Thank you!

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

                  微信群名称:华盟黑白之道二群   华盟-黑白之道⑦QQ群: 9430885

  • 上一篇编程:

  • 下一篇编程:
  • 网友评论
      验证码
     

    关注

    分享

    0

    讨论

    2

    猜你喜欢

    论坛最新贴