2016-02-22 13:12
浏览 113

Symfony2 - Doctrine - 更新后没有变更集

So i am sending an email when a certain value on an entity is changed. I only want the email to send after the update in case the update fails for what ever reason. so on the preUpdate I can do this

public function preUpdate(LifecycleEventArgs $args){

    if ($args->hasChangedField('value') && is_null($args->getOldValue('value'))) {


but i need to do this on postUpdate and as these methods are not available on postUpdate i refactored it to look like this:

public function postUpdate(LifecycleEventArgs $args){

    $entity      = $args->getEntity();
    $changeSet = $args->getEntityManager()->getUnitOfWork()->getEntityChangeSet($entity);

    if ($entity  instanceof Entity && isset( $changeSet['value'] ) && empty( $changeSet['value'][0] )) {

However this returns an empty change set, but changes have been made and can be seen in preUpdate. Can anyone see what i am doing wrong? help would be much appreciated :)

图片转代码服务由CSDN问答提供 功能建议

所以我在实体上的某个值发生变化时发送电子邮件。 我只希望在更新后发送电子邮件以防更新因任何原因而失败。 所以在preUpdate上我可以这样做

  public function preUpdate(LifecycleEventArgs $ args){
 if if($ args-> hasChangedField('value')&  & is_null($ args-> getOldValue('value'))){
 $ this-> sendEmail(); 
 \  n 


  public function postUpdate(LifecycleEventArgs $ args  ){
 $ entity = $ args-> getEntity(); 
 $ changeSet = $ args-> getEntityManager() - > getUnitOfWork() - > getEntityChangeSet($ entity); 
  if($ entity instanceof Entity&& isset($ changeSet ['value'])&& empty($ changeSet ['value'] [0])){
 $ this-> sendEmail();  

但是这会返回一个空的更改集,但是已经进行了更改,并且可以在preUpdate中看到。 谁能看到我做错了什么? 将非常感谢帮助:)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题