Finding out what changed via postUpdate listener in Symfony 2.1

后端 未结 4 1768
萌比男神i
萌比男神i 2021-02-20 18:14

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

4条回答
  •  没有蜡笔的小新
    2021-02-20 18:46

    You can find example in doctrine documentation.

    class NeverAliceOnlyBobListener
    {
        public function preUpdate(PreUpdateEventArgs $eventArgs)
        {
            if ($eventArgs->getEntity() instanceof User) {
                if ($eventArgs->hasChangedField('name') && $eventArgs->getNewValue('name') == 'Alice') {
                    $eventArgs->setNewValue('name', 'Bob');
                }
            }
        }
    }
    

提交回复
热议问题