> Hello, i have a listener for insert in database the changes in the tables
> to database. but the problme is with no insert to database.
> with eventlistener onFLush insert to database but no get ID the object
> insert.
> I'm trying PostPersist but no inserto to database.
> the code is:
> file config.yml:
> listenercrud:
> class: mio\mioBundle\ListenerCrud
> arguments: [@service_container]
> tags:
> - { name: doctrine.event_listener, event: postPersist}
> file ListenerCrud.php
> class ListenerCrud{
> protected $container;
> public function __construct(ContainerInterface $container)
> {
> $this->container = $container;
> }
> public function postPersist(LifecycleEventArgs $eventArgs)
> {
> $em = $eventArgs->getEntityManager();
> $uow = $em->getUnitOfWork();
> foreach ($uow->getScheduledEntityInsertions() as $entity) {
> if (!$entity instanceof Modificacion ) {
> $campos = "";
> $modificacion = new Modificacion();
> $modificacion->setFechamod(new \DateTime('now'));
> $className = join('', array_slice(explode('\\', get_class($entity)), -1));
> $modificacion->setEntidad($className);
> $modificacion->setIdentificador('aaaa');
> $modificacion->setTipo('Modificación');
> $securityContext = $this->container->get('security.context');
> $modificacion->setEmpleado($securityContext->getToken()->getUser());
> $changeset = $uow->getEntityChangeSet($entity);
> foreach ($changeset AS $field => $vals) {
> list($oldValue, $newValue) = $vals;
> $campos = $campos . $field .':'.$oldValue .' '.$newValue.' ';
> };
> $modificacion->setInfo($campos);
> $em->persist($modificacion);
> $classMetadata = $em->getClassMetadata(get_class($modificacion));
> $uow->computeChangeSet(