0

我使用这些捆绑包

https://github.com/hwi/HWIOAuthBundle
bundle:JMSI18nRoutingBundle
https://gist.github.com/danvbe/4476697

插入 i18n 后我的路线是

it__RG__hwi_oauth_connect                 ANY      ANY    ANY  /it/login/
en__RG__hwi_oauth_connect                 ANY      ANY    ANY  /en/login/
it__RG__hwi_oauth_connect_service         ANY      ANY    ANY  /it/login/service/{service}
en__RG__hwi_oauth_connect_service         ANY      ANY    ANY  /en/login/service/{service}
it__RG__hwi_oauth_connect_registration    ANY      ANY    ANY  /it/login/registration/{key}
en__RG__hwi_oauth_connect_registration    ANY      ANY    ANY  /en/login/registration/{key}
it__RG__hwi_oauth_service_redirect        ANY      ANY    ANY  /it/login/{service}
en__RG__hwi_oauth_service_redirect        ANY      ANY    ANY  /en/login/{service}
it__RG__facebook_login                    ANY      ANY    ANY  /it/login/check-facebook
en__RG__facebook_login                    ANY      ANY    ANY  /en/login/check-facebook
it__RG__twitter_login                     ANY      ANY    ANY  /it/login/check-twitter
en__RG__twitter_login                     ANY      ANY    ANY  /en/login/check-twitter

但是当我尝试去这里时出现此错误:“/en/login/check-facebook”(或在重定向 facebook 或 twitter 后出现此错误)

No resource owner with name 'check-facebook'.

/app/config/routing.yml

#HWIOAuthBundle routes
hwi_oauth_security:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix: /login

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix: /login

hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /login

facebook_login:
    pattern: /login/check-facebook

twitter_login:
    pattern: /login/check-twitter
4

1 回答 1

0

我找到了一个解决方案,不是最好的解决方案,但有效

在我的主页上

主页控制器

公共函数 indexAction()
{
    $request = $this->get('request');
    /**
     * 将其存储到会话中的用户语言
     */
    $sessionId = $this->get("session");
    if($sessionId->get("lingua")==""){
        $this->get('session')->set('lingua', $request->getLocale());
    }

    返回数组();

}

在已被覆盖的 FOSUserBundle 的另一个包中

UserBundle/Controller/RegistrationController.php(例如)

公共函数 customAction() {

    /**
     * 将其存储到会话中的用户语言
     */
    $sessionId = $this->container->get("session");
    if($sessionId->get("lingua")==""){
        $this->container->get("session")->set('lingua', $this->container->get('request')->getLocale());
    }

    返回数组(

    );
}

然后我创建一个服务,如:http ://symfony.com/doc/current/cookbook/session/locale_sticky_session.html

服务.xml

服务:
    acme_locale.locale_listener:
        类:Acme\LocaleBundle\EventListener\LocaleListener
        参数:["%kernel.default_locale%",@session]
        标签:
            - {名称:kernel.event_subscriber}

语言环境监听器


命名空间 Acme\LocaleBundle\EventListener;

使用 Symfony\Component\HttpKernel\Event\GetResponseEvent;
使用 Symfony\Component\HttpKernel\KernelEvents;
使用 Symfony\Component\EventDispatcher\EventSubscriberInterface;
使用 Symfony\Component\HttpFoundation\Session;


SnLocaleListener 类实现 EventSubscriberInterface
{
    私人 $defaultLocale;
    私人$会话;


    公共函数 __construct($defaultLocale = 'it', $session)
    {
        $this->defaultLocale = $defaultLocale;
        $this->session = $session;
    }

    公共函数 onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        if (!$request->hasPreviousSession()) {
            返回;
        }

        //incapsula la lingua in sessione se siste
        $locale_session = $this->session->get('lingua');

        if ($locale_session == "") {

            // prova a vedere se il locale sia stato imppostato come parametro _locale di una rotta
            if ($locale = $request->attributes->get('_locale')) {
                $request->getSession()->set('_locale', $locale);
            } 别的 {
                // se non trova un locale esplito in questa Richiesta, 美国 quello della sessione
                $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale));
            }

        } 别的 {
            $request->setLocale($request->getSession()->get('_locale', $locale_session));
            $request->getSession()->set('_locale', $locale_session);
            $request->attributes->set('_locale', $locale_session);
        }


    }

    公共静态函数 getSubscribedEvents()
    {
        返回数组(
            // deve essere registrato prima dell'ascoltatore predefinito di locale
            KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
        );
    }
}

/app/config/security.yml

..
认证:
                记住我:是的
                资源所有者:
                    facebook: "/%locale%/login/check-facebook"
                    twitter: "/%locale%/login/check-twitter"
                登录路径:fos_user_security_ripeti_login
                failure_path:fos_user_security_ripeti_login
..

对不起我的英语不完美..这个解决方案对我有用,它不会是最好的

于 2013-10-04T15:25:58.207 回答