我在服务中使用原则时遇到问题:
致命错误:在第 37 行的 /var/www/Symfony/src/mio/mioBundle/AuthenticationHandler.php 中的非对象上调用成员函数 persist()
该服务的代码是:
services:
authentication_handler:
class: mio\mioBundle\AuthenticationHandler
arguments: [@router , @doctrine.orm.entity_manager ]
calls:
- [ setContainer, [ @service_container ] ]
监听器的代码是:
class AuthenticationHandler extends ContainerAware implements AuthenticationSuccessHandlerInterface{
protected $router;
protected $em;
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
public function __constructor(EntityManager $entityManager)
{
$this->em = $entityManager;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$empleado = $token->getUser();
$empleado->setNombre("abeeeer");
$this->em->persist($empleado); //line 37
$this->em->flush();
//return new Response($token->getUsername());
return new RedirectResponse($this->router->generate('familia'));
}
}