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

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

问题描述

有没有办法在afterSave中访问原始数据?
我想记录重要数据的变化。



使用$ entity-> isNew()我可以检查它是插入还是更新,

解决方案

您可以通过 Entity :: getOriginal () Entity :: extractOriginal()。如果你想得到所有改变的字段,结合后一个与 Entity :: visibleProperties(),像:



< pre class =lang-php prettyprint-override> debug($ entity-> extractOriginal($ entity-> visibleProperties()));

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



另请参阅




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

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

解决方案

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.

See also

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

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