0
我創建了UserActivityListener
來記錄用戶操作時做類似CRUD的任何操作。但我想在獲得$實體字段數據時遇到問題:CakePHP 3:如何獲取原始實體數據和修改的實體數據?
例如:我得到了表Users
(id,email,password);
// I do override afterSave event
public function afterSave(Event $event, Entity $entity, ArrayObject $options) {
//Log field entity
if($entity->isNew()) {
Log::write('info', $entity->get('email'));
// This one is fine
} else {
Log::write('info-old-field-data', $entity->get('email'));
// old data of field was fine because entity does not change yet
Log::write('info-new-field-data', $entity->get('email'));
// Wrong, entity not yet change, Please help me to get new data.
}
}
如何在afterSave函數中獲取實體的新數據? 如何檢查哪些字段被修改,哪些不是?
http://stackoverflow.com/q/26548511/1127933 – Salines