mscherer 1 年之前
父节点
当前提交
c485074b63
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      docs/Behavior/AfterSave.md

+ 6 - 1
docs/Behavior/AfterSave.md

@@ -2,6 +2,7 @@
 
 
 A CakePHP behavior to allow the entity to be available inside afterSave() callback in the state
 A CakePHP behavior to allow the entity to be available inside afterSave() callback in the state
 it was before the save.
 it was before the save.
+It also allows it to be available outside of the afterSave() callback later on, where needed.
 
 
 ## Introduction
 ## Introduction
 It takes a clone of the entity from beforeSave(). This allows all the
 It takes a clone of the entity from beforeSave(). This allows all the
@@ -23,7 +24,7 @@ Then inside your table you can do:
 ```php
 ```php
 public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
 public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
     $entityBefore = $this->getEntityBeforeSave();
     $entityBefore = $this->getEntityBeforeSave();
-    // Now you can check isDirty() etc
+    // Now you can check diff dirty fields etc
 }
 }
 ```
 ```
 
 
@@ -36,3 +37,7 @@ $entityBefore = $table->getEntityBeforeSave();
 If you are using save(), make sure you check the result and that the save was successful.
 If you are using save(), make sure you check the result and that the save was successful.
 Only call this method after a successful save operation.
 Only call this method after a successful save operation.
 Otherwise, there will not be an entity stored and you would get an exception here.
 Otherwise, there will not be an entity stored and you would get an exception here.
+
+Also note that by default the "dirty" fields should be present in the afterSave() callback still.
+Same for "original" values.
+So if your needs are bound to that callback only, this behavior might not be needed usually.