我已经手动创建了登录表单并在安全控制器中设置了凭据,如下所示
public function loginCheckAction()
{
$request = $this->getRequest();
$session = $request->getSession();
$oem = $this->getDoctrine()->getEntityManager();
$username = $request->get('_username');
$password = $request->get('_password');
if($username){
$user = $oem->getRepository('AdminEmployeeBundle:Employees')->loadUserByUsername($username);
if($user){
$dbpassword = $password;
if($dbpassword == $user->getPassword()){
// secured and redirect
$token = new UsernamePasswordToken($user,null,'main',array('ROLE_ADMIN'));
// give it to the security context
$this->container->get('security.context')->setToken($token);
return $this->redirect($this->generateUrl('_employeeList'));
}
else{
$this->get('session')->setFlash('error','Please check username password');
}
}
return $this->redirect($this->generateUrl('login'));
}
现在我想在员工控制器中使用它,但我不知道如何使用它