通过 Symfony 2.1 中的 postUpdate 监听器找出发生了什么变化 [英] Finding out what changed via postUpdate listener in Symfony 2.1

查看:21
本文介绍了通过 Symfony 2.1 中的 postUpdate 监听器找出发生了什么变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 postUpdate 监听器,我想知道更新前的值是什么,更新后数据库条目的值是什么.在 Symfony 2.1 中有没有办法做到这一点?我查看了 getUnitOfWork() 中存储的内容,但由于更新已经发生,因此它是空的.

I have a postUpdate listener and I'd like to know what the values were prior to the update and what the values for the DB entry were after the update. Is there a way to do this in Symfony 2.1? I've looked at what's stored in getUnitOfWork() but it's empty since the update has already taken place.

推荐答案

找到解决方案 这里.我需要的实际上是 preUpdate() 的一部分.我需要在 LifecycleEventArgs 上调用 getEntityChangeSet().

Found the solution here. What I needed was actually part of preUpdate(). I needed to call getEntityChangeSet() on the LifecycleEventArgs.

我的代码:

public function preUpdate(EventLifecycleEventArgs $eventArgs)
{   
    $changeArray = $eventArgs->getEntityChangeSet();

    //do stuff with the change array

}

这篇关于通过 Symfony 2.1 中的 postUpdate 监听器找出发生了什么变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆