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
Php 使用fosuserBundle自动登录_Php_Symfony_Fosuserbundle_Autologin - Fatal编程技术网

Php 使用fosuserBundle自动登录

Php 使用fosuserBundle自动登录,php,symfony,fosuserbundle,autologin,Php,Symfony,Fosuserbundle,Autologin,我可以用fosuserBundle自动登录,当他访问页面添加子句时,他是自动登录,当他添加页面添加文章时,他会自动重定向到登录页面,但我的目标是自动登录 路由: ajouterapps: path: /ajouterapps defaults: { _controller: MedBundle:Apps:ajouter } 代码控制器: public function ajouterAction() { $em = $this->getDoctrine(); $

我可以用fosuserBundle自动登录,当他访问页面添加子句时,他是自动登录,当他添加页面添加文章时,他会自动重定向到登录页面,但我的目标是自动登录

路由:

ajouterapps:
  path:     /ajouterapps
  defaults: { _controller: MedBundle:Apps:ajouter }
代码控制器:

public function ajouterAction() 
{
  $em = $this->getDoctrine();
  $repo  = $em->getRepository("UserBundle:User"); //Entity Repository
  $user = $this->getUser();

  if (!$user) {
    throw new UsernameNotFoundException("User not found");
  } else {
    $token = new UsernamePasswordToken($user, null, "your_firewall_name", $user->getRoles());
    $this->get("security.context")->setToken($token); //now the user is logged in

    //now dispatch the login event
    $request = $this->get("request");
    $event = new InteractiveLoginEvent($request, $token);
    $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
  }

  $msg = 'ajouter Apps';
  $em = $this->getDoctrine()->getManager();
  $app = new Apps();
  $form = $this->createForm(new AppsType, $app);
  $request = $this->getRequest();

  if ($request->getMethod() == 'POST') {
    $form->handleRequest($request);

    $app->upload(); 
    $em->persist($app);
    $em->flush();
    $msg = 'Apps ajouter avec success';
  }

  return $this->render('MedBundle:Apps:ajouter.html.twig',array(
      'form'=>$form->createView(),
      'msg'=>$msg
    )
  );
}

什么是解决方案,并提前感谢您

请帮助我…请看这里的完整答案:谢谢您的帮助,我看到了这个主题,但我发现了相同的问题,当他添加文章时,我发现登录页面,也就是说,自动登录不正常“您的防火墙名称”是什么在主应用程序config.yml上?这是我在app/config/config.yml中的防火墙请帮我…请看这里的完整答案:谢谢你的帮助,我看到了这个主题,但我发现了相同的问题,当他访问添加文章的页面时,我发现了登录页面,也就是说,自动登录不是Walk“你的防火墙名称”是什么在主app config.yml上?这是我在app/config/config.yml中的防火墙