Php 在定制服务symfony2中插入原则

Php 在定制服务symfony2中插入原则,php,symfony,login,persist,Php,Symfony,Login,Persist,我在服务中使用条令时遇到问题: 致命错误:在第37行的/var/www/Symfony/src/mio/mioBundle/AuthenticationHandler.php中对非对象调用成员函数persist() 该服务的代码是: services: authentication_handler: class: mio\mioBundle\AuthenticationHandler arguments: [@router , @doctrine.orm.

我在服务中使用条令时遇到问题:

致命错误:在第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'));
    }
}

构造函数中可以有多个参数:

public function __construct(RouterInterface $router, EntityManager $em)
{
    $this->router = $router;
    $this->em = $em;
}
但是一个类中不能有多个构造函数,
\u构造函数
不是构造函数方法名,所以应该删除该方法

此外,您不必扩展
containerware
,因为您正在注入所需的服务。这意味着你不需要这个:

calls:
    - [ setContainer, [ @service_container ] ]