通过Symfony 2.1中的postUpdate侦听器找出改变的内容 [英] Finding out what changed via postUpdate listener in Symfony 2.1

查看:85
本文介绍了通过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.

推荐答案

找到解决方案here 。实际上我需要的是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(Event\LifecycleEventArgs $eventArgs)
{   
    $changeArray = $eventArgs->getEntityChangeSet();

    //do stuff with the change array

}

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

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