cakephp 3 afterSave 中的原始数据 [英] cakephp 3 original data in afterSave

查看:22
本文介绍了cakephp 3 afterSave 中的原始数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在afterSave中访问原始数据?我想记录重要数据的更改.

Is there any way to access original data in afterSave? I would like to log the changes on important data.

使用 $entity->isNew() 我可以检查它是插入还是更新,但我怎样才能获得更改的内容?

With $entity->isNew() I could check if it was an insert or an update, but how can I get what changed?

推荐答案

您可以通过 Entity::getOriginal()Entity::extractOriginal() 访问原始值>.如果要获取所有更改的字段,请将后一个与 Entity::visibleProperties() 结合起来,例如:

You can access the original values via Entity::getOriginal() or Entity::extractOriginal(). If you want to get all changed fields, combine the latter one with Entity::visibleProperties(), something like:

debug($entity->extractOriginal($entity->visibleProperties()));

这应该返回所有更改字段的原始值.

This should return the original values of all changed fields.

另见

这篇关于cakephp 3 afterSave 中的原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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