Symfony2 Gedmo Loggable在刷新呼叫时崩溃

时间:2014-11-24 06:50:35

标签: php symfony doctrine flush

我有一个Symfony2项目,我在使用Gedmo的Loggable扩展时遇到了问题。

我有一个正在构建和提交的表单,通过验证,但是当调用$EntityManager->flush()将表单数据添加到数据库(带有Doctrine的MySQL)时,我得到以下结果:

FatalErrorException: Error: Call to undefined method Path\To\My\Entity\Class::setAction() 
in /path/to/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/LoggableListener.php line 225

at ErrorHandler->handleFatal() in /path/to/vendor/symfony/symfony/src/Symfony/Component/Debug/ErrorHandler.php line 0
at LoggableListener->createLogEntry() in /path/to/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/LoggableListener.php line 188
at LoggableListener->onFlush() in /path/to/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php line 61
at ContainerAwareEventManager->dispatchEvent() in /path/to/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 306
at UnitOfWork->commit() in /path/to/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 355
at EntityManager->flush() in /Path/To/My/Bundle/Controller.php line 364
at Controller->addEntityAction() in /Path/To/app/bootstrap.php.cache line 2891
at ??call_user_func_array() in /Path/To/app/bootstrap.php.cache line 2891
at HttpKernel->handleRaw() in /Path/To/app/bootstrap.php.cache line 2865
at HttpKernel->handle() in /Path/To/app/bootstrap.php.cache line 2994
at ContainerAwareHttpKernel->handle() in /Path/To/app/bootstrap.php.cache line 2274
at Kernel->handle() in /Path/To/web/app_dev.php line 28
at ??{main}() in /Path/To/web/app_dev.php line 0

LoggableListner.php第188行是:

    foreach ($ea->getScheduledObjectInsertions($uow) as $object) {
        $this->createLogEntry(self::ACTION_CREATE, $object, $ea);
    }

并且第188行foreach周围的完整函数是:

public function onFlush(EventArgs $eventArgs)
{
    $ea = $this->getEventAdapter($eventArgs);
    $om = $ea->getObjectManager();
    $uow = $om->getUnitOfWork();

    foreach ($ea->getScheduledObjectInsertions($uow) as $object) {
        $this->createLogEntry(self::ACTION_CREATE, $object, $ea);
    }
    foreach ($ea->getScheduledObjectUpdates($uow) as $object) {
        $this->createLogEntry(self::ACTION_UPDATE, $object, $ea);
    }
    foreach ($ea->getScheduledObjectDeletions($uow) as $object) {
        $this->createLogEntry(self::ACTION_REMOVE, $object, $ea);
    }
}

LoggableListner.php第225行是:

        /** @var \Gedmo\Loggable\Entity\LogEntry $logEntry */
        $logEntry = $logEntryMeta->newInstance();

我的实体具有Loggable的标准Symfony2注释,即:

use Gedmo\Mapping\Annotation as Gedmo;

/**
* @Gedmo\Loggable(logEntryClass="My\Bundles\ThisBundle\ThisEntity")
*/

/**
* @ORM\Column(type="string", length=30, nullable=false)
* @Assert\Length(max=30)
* @Gedmo\Versioned
*/
protected $name;

我不知道setAction()来电的来源。我班上没有任何名字" action"并且没有getAction()addAction()removeAction()等功能或方法(也不应该从我的理解中获得。)

感谢您的任何见解和帮助!

1 个答案:

答案 0 :(得分:3)

因此,在仔细查看堆栈跟踪并查看Loggable函数之后,我突然意识到错误显然来自于我可以尝试从我的某个实体实现函数的loggable,这告诉我某个地方我在某个地方有一个类它不应该(因为我希望Loggable使用自己的类和函数,而不是我的)。

我因此改变了

/**
* @Gedmo\Loggable(logEntryClass="My\Bundles\ThisBundle\ThisEntity")
*/

/**
* @Gedmo\Loggable
*/ 

这意味着它使用自己的类来执行日志记录 - 瞧。没有更多的错误。