Reputation: 291
I have this code but I have a problem to insert object $modificacion
in database.
class ListenerCrud{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function preUpdate(PreUpdateEventArgs $eventArgs){
if ($eventArgs->getEntity() instanceof Usuario) {
$em = $eventArgs->getEntityManager();
$modificacion = new Modificacion();
$modificacion->setFechamod(new \DateTime('now'));
$modificacion->setEntidad('Usuario');
$modificacion->setTipo('uupdate');
$securityContext = $this->container->get('security.context');
$modificacion->setEmpleado($securityContext->getToken()->getUser());
$modificacion->setInfo('hi');
$em->persist($modificacion);
$classMetadata = $em->getClassMetadata(get_class($modificacion));
$em->getUnitOfWork()->computeChangeSet($classMetadata, $modificacion);
}
}
}
In the config.yml
, I have:
listenercrud:
class: mio\mioBundle\ListenerCrud
arguments: [@service_container]
tags:
- { name: doctrine.event_listener, event: PreUpdate}
Upvotes: 2
Views: 733
Reputation: 5304
The event name, in your YAML file, should be "preUpdate", not "PreUpdate".
listenercrud:
class: mio\mioBundle\ListenerCrud
arguments: [@service_container]
tags:
- { name: doctrine.event_listener, event: preUpdate }
Upvotes: 1