2013-02-22 46 views

回答

2

有一个用户对象,您可以登录/验证用户编程

$token = new UsernamePasswordToken($user, $user->getPassword(), 
             "public", $user->getRoles()); 

    $this->get("security.context")->setToken($token); 

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

你需要有这个类包括

use Symfony\Component\EventDispatcher\EventDispatcher, 
    Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken, 
    Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 
+0

这个工作!谢谢! – 2013-02-26 10:50:02