PostsTable.php 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace TestApp\Model\Table;
  3. use ArrayObject;
  4. use Cake\Datasource\EntityInterface;
  5. use Cake\Event\EventInterface;
  6. use Tools\Model\Table\Table;
  7. class PostsTable extends Table {
  8. /**
  9. * @var array<string>
  10. */
  11. public array $dirtyFieldsBefore = [];
  12. /**
  13. * @var array<string>
  14. */
  15. public array $dirtyFieldsAfter = [];
  16. /**
  17. * @param \Cake\Event\EventInterface $event
  18. * @param \Cake\Datasource\EntityInterface $entity
  19. * @param \ArrayObject $options
  20. *
  21. * @return void
  22. */
  23. public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void {
  24. $this->dirtyFieldsBefore = $entity->getDirty();
  25. }
  26. /**
  27. * @param \Cake\Event\EventInterface $event
  28. * @param \Cake\Datasource\EntityInterface $entity
  29. * @param \ArrayObject $options
  30. *
  31. * @return void
  32. */
  33. public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void {
  34. $this->dirtyFieldsAfter = $entity->getDirty();
  35. }
  36. }