Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在symfony2中获取会话值我使用fosuserbundle_Php_Symfony_Session_Request_Fosuserbundle - Fatal编程技术网

Php 如何在symfony2中获取会话值我使用fosuserbundle

Php 如何在symfony2中获取会话值我使用fosuserbundle,php,symfony,session,request,fosuserbundle,Php,Symfony,Session,Request,Fosuserbundle,我正在使用fosuserbundle,这是我在FOSUBUserProvider类中的函数: public function connect(UserInterface $user, UserResponseInterface $response) { // and here i want to get session value like: $session = $request->getSession(); $session->g

我正在使用fosuserbundle,这是我在FOSUBUserProvider类中的函数:

public function connect(UserInterface $user, UserResponseInterface $response)
    {

      // and here i want to get session value like:
       $session = $request->getSession();
       $session->get('value1');
     //
}

您需要在服务声明中插入会话

然后将其添加到
FOSUserProvider
类的构造函数中

services.yml
和服务部分添加
@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]
在上面的类中声明
$session
和$em变量
connect
函数并添加以下构造函数

public function __construct(UserManager $userManager, Array $properties, Session $session, EntityManager $em)
    {
        $this->session=$session;
        $this->em=$em;
        parent::__construct($userManager, $properties);
    }
在函数
Connect
中,您可以将其作为

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
     . 
     .
     .
}

谢谢你的回答,我这么做了,但是如何在连接函数中获得$session如果你已经完成了上述操作,那么你可以通过
$value=$this->session->get('value1')获得它谢谢你让我开心:Ddo你知道如何使用$em=$this->getDoctrine()->getManager();在这个函数中