Symfony 使用Gedmo转换OnFlush事件

Symfony 使用Gedmo转换OnFlush事件,symfony,Symfony,我的听众有问题 public function onFlush(OnFlushEventArgs $args) { ini_set('max_execution_time', 30000); ini_set('memory_limit', '512M'); $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledE

我的听众有问题

public function onFlush(OnFlushEventArgs $args)
{
    ini_set('max_execution_time', 30000);
    ini_set('memory_limit', '512M');

    $em = $args->getEntityManager();
    $uow = $em->getUnitOfWork();

    foreach ($uow->getScheduledEntityInsertions() as $entity) {
        if($entity->getTranslatable() == 1){
            $translation = $this->translate($entity);

            $repository = $em->getRepository('ByJM\AdminBundle\Entity\Translation\ChambreTranslation');

            $repository
                ->translate($entity, 'nom', 'fr', $translation['fr'])
                ->translate($entity, 'nom', 'en', $translation['en'])
                ->translate($entity, 'nom', 'es', $translation['es'])
                ->translate($entity, 'nom', 'it', $translation['it'])
                ->translate($entity, 'nom', 'nl', $translation['nl'])
                ->translate($entity, 'nom', 'pt', $translation['pt'])
            ; 

            $md = $em->getClassMetadata('ByJM\AdminBundle\Entity\Chambre');
            $uow->recomputeSingleEntityChangeSet($md, $entity);
        }
    }

    foreach ($uow->getScheduledEntityUpdates() as $entity) {
        if($entity->getTranslatable() == 1){
            $translation = $this->translate($entity);

            $repository = $em->getRepository('ByJM\AdminBundle\Entity\Translation\ChambreTranslation');

            $repository
                ->translate($entity, 'nom', 'fr', $translation['fr'])
                ->translate($entity, 'nom', 'en', $translation['en'])
                ->translate($entity, 'nom', 'es', $translation['es'])
                ->translate($entity, 'nom', 'it', $translation['it'])
                ->translate($entity, 'nom', 'nl', $translation['nl'])
                ->translate($entity, 'nom', 'pt', $translation['pt'])
            ; 

            $em->persist($entity);

            $md = $em->getClassMetadata('ByJM\AdminBundle\Entity\Chambre');
            $uow->recomputeSingleEntityChangeSet($md, $entity);
        }
    }         
}
我有一个错误: 执行“插入到chambre_翻译(区域设置、对象类、字段、外键、内容)值(?,,,?,?)时发生异常”:

SQLSTATE[HY093]:参数编号无效:未绑定任何参数

如果有人能给我一个解决方案,那就太棒了


提前感谢。

这与Gedmo无关

如中所述,调用了onFlush,所有更改都已计算,如果更改实体或创建新实体,则需要刷新这些更改

因此,您需要添加一个
$em->persist($entity)

你能试试这个吗?请

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

     $entities = array_merge(
         $uow->getScheduledEntityInsertions(),
         $uow->getScheduledEntityUpdates()
     );

     foreach ($entities as $entity) {
         if($entity->getTranslatable() == 1){
               $translation = $this->translate($entity);

               $repository = $em->getRepository('ByJM\AdminBundle\Entity\Translation\ChambreTranslation');

               $repository
                     ->translate($entity, 'nom', 'fr', $translation['fr'])
                     ->translate($entity, 'nom', 'en', $translation['en'])
                     ->translate($entity, 'nom', 'es', $translation['es'])
                     ->translate($entity, 'nom', 'it', $translation['it'])
                     ->translate($entity, 'nom', 'nl', $translation['nl'])
                     ->translate($entity, 'nom', 'pt', $translation['pt']); 

               $em->persist($entity);
               $md = $em->getClassMetadata(get_class($entity));
               $uow->recomputeSingleEntityChangeSet($md, $entity);
         }

     }
}

这与Gedmo无关

如中所述,调用了
onFlush,所有更改都已计算,如果更改实体或创建新实体,则需要刷新这些更改

因此,您需要添加一个
$em->persist($entity)

你能试试这个吗?请

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

     $entities = array_merge(
         $uow->getScheduledEntityInsertions(),
         $uow->getScheduledEntityUpdates()
     );

     foreach ($entities as $entity) {
         if($entity->getTranslatable() == 1){
               $translation = $this->translate($entity);

               $repository = $em->getRepository('ByJM\AdminBundle\Entity\Translation\ChambreTranslation');

               $repository
                     ->translate($entity, 'nom', 'fr', $translation['fr'])
                     ->translate($entity, 'nom', 'en', $translation['en'])
                     ->translate($entity, 'nom', 'es', $translation['es'])
                     ->translate($entity, 'nom', 'it', $translation['it'])
                     ->translate($entity, 'nom', 'nl', $translation['nl'])
                     ->translate($entity, 'nom', 'pt', $translation['pt']); 

               $em->persist($entity);
               $md = $em->getClassMetadata(get_class($entity));
               $uow->recomputeSingleEntityChangeSet($md, $entity);
         }

     }
}