how to get session value inside symfony2 i use fosuserbundle

孤人 提交于 2019-12-06 16:41:55

you need to inject Session in your Services Declaration,

and then add it in constructor of FOSUserProvider class,

in services.yml and services section add @session

parameters:
    my_user_provider.class: Auth\UserBundle\Security\Core\User\FOSUBUserProvider

services:
    my_user_provider:
        class: "%my_user_provider.class%"
        #this is the place where the properties are passed to the UserProvider class
        arguments: [@fos_user.user_manager,{facebook: facebookID},@session,@doctrine.orm.entity_manager]

declare $session and $em variable in your class above connect function and add following constructor,

public function __construct(UserManager $userManager, Array $properties, Session $session, EntityManager $em)
    {
        $this->session=$session;
        $this->em=$em;
        parent::__construct($userManager, $properties);
    }

in function Connect you can get it as,

public function connect(UserInterface $user, UserResponseInterface $response)
    {
       $value=$this->session->get('value1');
       $em=$this->em;  // or directly use $this->em->flush(); or whatever you want
     . 
     .
     .
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!