Created
August 23, 2018 04:34
-
-
Save angelxmoreno/6a19d944569d17e8a913734a4ce414fe to your computer and use it in GitHub Desktop.
CakePHP 3 Behavior to adds a Model\Table callback triggered after a save or after a delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FiveTalents\Model\Behavior; | |
use Cake\Datasource\EntityInterface; | |
use Cake\Event\Event; | |
use Cake\ORM\Behavior; | |
/** | |
* AfterSaveOrDelete behavior | |
*/ | |
class AfterSaveOrDeleteBehavior extends Behavior | |
{ | |
public function afterSave( | |
Event $event, | |
EntityInterface $entity, | |
$options | |
) { | |
$this->callAfterSaveOrDeleteOnTable($event, $entity, $options); | |
} | |
public function afterDelete(Event $event, EntityInterface $entity, $options) | |
{ | |
$this->callAfterSaveOrDeleteOnTable($event, $entity, $options); | |
} | |
protected function callAfterSaveOrDeleteOnTable(Event $event, EntityInterface $entity, $options) | |
{ | |
call_user_func([$this->getTable(), 'afterSaveOrDelete'], $event, $entity, $options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment