2016-05-03 16 views
0

In meinem Controller habe ich Lastname in einer Einheit aktualisiertLehre EventSubscriber

public function testAction(){ 
     $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager'); 
     $entity = $objectManager->getRepository('Profiling\Entity\Profile')->find(18); 
     $entity->setLastname('A'); 
     $objectManager->flush(); 
     return $this->response; 
    } 

und meine EventSubscriber

public function onFlush(OnFlushEventArgs $args) 
{ 
    $em = $args->getEntityManager(); 
    $uow = $em->getUnitOfWork(); 
    foreach ($uow->getScheduledEntityUpdates() as $updated) { 

     if ($updated instanceof Profile) { 
      $updated->setBalancelog($updated->getBalance()); 
      echo $updated->getLastname(); 
     } 
    } 

    foreach ($uow->getScheduledEntityInsertions() as $insertion) { 
     if ($insertion instanceof Profile) { 
      $profile = $insertion; 
      $profile->setBalancelog($profile->getBalance()); 
     } 
    } 


$uow->computeChangeSets(); 

} 

es Echos "A" in meinem Fall Teilnehmer aber nicht gespeichert bekommt. Was vermisse ich? Vielen Dank!

Antwort

0

von recomputeSingleEntityChangeSet

if ($updated instanceof Profile) { 
      $updated->setBalancelog($updated->getBalance()); 

      $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('Profiling\Entity\Profile'),$updated); 
      echo $updated->getLastname(); 
     } 
FIXED