-2

hello i hace problem this code :

ListenerCrud.php

<?php

namespace mio\mioBundle;

use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\EntityManager;
use mio\mioBundle\Entity\Log;
use Symfony\Component\HttpFoundation\Response;

class ListenerCrud{

    public function preUpdate(PreUpdateEventArgs $eventArgs){

        if ($eventArgs->getEntity() instanceof Usuario){
        $entity = $eventArgs->getEntity();
        $entityManager = $eventArgs->getEntityManager();
        $log = new Log();
        $entityManager->persist($log);
        $entityManager->flush();
        }
    }
}
?>

config.yml :

listenercrud:
    class: mio\mioBundle\ListenerCrud
    tags:
        - { name: doctrine.event_listener, event: preUpdate}

but no create log in database. help me please.thanks

4

1 回答 1

3

在这种情况下 $entityManager->persist() 不起作用,因为他不能在 preUpdate 事件中被调用。 http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preupdate

也许您可以使用 postUpdate 事件 http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#postupdate-postremove-postpersist

于 2012-10-05T13:51:29.520 回答