本文介绍了SonataAdminBundle - 检查 `preUpdate` 钩子中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以检查 preUpdate
钩子?我正在寻找类似 preUpdate
hasChangedField($fieldName)
Doctrine 功能.有什么想法吗?
Is it possible to check if field was changed on preUpdate
hook? I'm looking for something like preUpdate
hasChangedField($fieldName)
Doctrine functionality. Any ideas?
推荐答案
这个问题有点类似于这个
您的解决方案只是将旧对象的字段与新对象的字段进行比较,看看它的不同之处.
Your solution is just to compare the field of the old object with the new one and see where it differs.
例如:
public function preUpdate($newObject)
{
$em = $this->getModelManager()->getEntityManager($this->getClass());
$originalObject = $em->getUnitOfWork()->getOriginalEntityData($newObject);
if ($newObject->getSomeField() !== $originalObject['fieldName']) {
// Field has been changed
}
}
这篇关于SonataAdminBundle - 检查 `preUpdate` 钩子中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!