gpt4 book ai didi

symfony2 达到最大函数嵌套级别 '100',中止!与学说事件监听器

转载 作者:行者123 更新时间:2023-12-02 22:00:48 26 4
gpt4 key购买 nike

我有事件监听器 preUpdate

public function preUpdate(PreUpdateEventArgs $args) {        
$user = $args->getEntity();
if($user instanceof \iTracker\UserBundle\Entity\User) {
if($args->hasChangedField('userGroup')) {

$old = $args->getOldValue('userGroup');
$new = $args->getNewValue('userGroup');

$em = $args->getEntityManager();

$old->setAmount($old->getAmount() - 1);
$em->persist($old);

$new->setAmount($new->getAmount() + 1);
$em->persist($new);
$em->flush();
}
}
}

提交表单后,我得到 FatalErrorException: Error: Maximum function nesting level of '100' reached, aborting!在/var/www/issue/app/cache/dev/classes.php 第 6123 行

in /var/www/issue/app/cache/dev/classes.php line 6123 at ErrorHandler->handleFatal() in /var/www/issue/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php line 0 at NormalizerFormatter->normalize() in /var/www/issue/app/cache/dev/classes.php line 6198 at LineFormatter->normalize() in /var/www/issue/app/cache/dev/classes.php line 6112 at NormalizerFormatter->format() in /var/www/issue/app/cache/dev/classes.php line 6172 at LineFormatter->format() in /var/www/issue/app/cache/dev/classes.php line 6320 at AbstractProcessingHandler->handle() in /var/www/issue/app/cache/dev/classes.php line 6646 at Logger->addRecord() in /var/www/issue/app/cache/dev/classes.php line 6710 at Logger->debug() in /var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php line 72 at DbalLogger->log() in /var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php line 50 at DbalLogger->startQuery() in /var/www/issue/vendor/doctrine/dbal/lib/Doctrine/DBAL/Logging/LoggerChain.php line 50 at LoggerChain->startQuery() in /var/www/issue/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 774 at Connection->executeUpdate() in /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 447 at BasicEntityPersister->_updateTable() in /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 357 at BasicEntityPersister->update() in /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 984 at UnitOfWork->executeUpdates() in /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 317 at UnitOfWork->commit() in /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 355 at EntityManager->flush() in /var/www/issue/src/iTracker/UserBundle/Listener/UserGroupAmount.php line 41 and this

  • 在 UserGroupAmount->preUpdate() 中/var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php第61行
  • 在 ContainerAwareEventManager->dispatchEvent() 中/var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php980行
  • 在 UnitOfWork->executeUpdates() 中/var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php第317行
  • 在 UnitOfWork->commit() 中/var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php第355行
  • 在 EntityManager->flush() 中/var/www/issue/src/iTracker/UserBundle/Listener/UserGroupAmount.php第 41 行

并且循环了这5个错误,导致了这个异常

最佳答案

@meze 是对的,在 *Flush* 事件中使用 flush 会导致循环。

但是有一个快速的解决方法可以让您仍然这样做: $eventManager = $this -> em -> getEventManager();

// Remove event, if we call $this->em->flush() now there is no infinite recursion loop!
$eventManager -> removeEventListener('onFlush', $this);

// ...

// Re-attach since we're done
$eventManager -> addEventListener('onFlush', $this);

出现在:Doctrine2 Event Listener: persisting in onFlush() | Benedikt Wolters

关于symfony2 达到最大函数嵌套级别 '100',中止!与学说事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com