Auditor plugin for CakePHP
Requirements
* CakePHP 3.4.0+
* PHP 5.6+
Installation
You can install this plugin into your CakePHP application using composer., (*1)
The recommended way to install composer packages is:, (*2)
composer require angelxmoreno/cakephp-auditor
Then you need to apply two behaviors:, (*3)
- One on your UsersTable ( the Auditors )
$this->addBehavior('Auditor.Auditor');
- Another on your tables you with to track
$this->addBehavior('Auditor.Audit');
Options
For the AuditBehavior you have the following default options:, (*4)
[
'attach' => true,
'reverse' => false,
'skip_fields' => [],
]
attach: Boolean ( default true)
Whether or not the behavior should attach the given table to the AuditsTable as a HasMany association, (*5)
reverse: Boolean ( default false)
Whether or not the behavior should attach the AuditsTable to the given table as a belongsTo association, (*6)
skip_fields: Array ( default empty array)
The fields that should be ignored when saving the diff of the previous
and current
fields., (*7)
[ It is recommended to add your created
and modified
fields], (*8)
I personally use a BaseTable and extend all my Table classes from that. It makes it easier to add traits, methods and other
goodies to all my Table classes. I created a convenience method to conditionally add the Audit behavior when the Table class
is not the AuditsTable. You can make use of it like so:, (*9)
\Auditor\Model\Behavior\AuditBehavior::makeAuditable($this, [
'attach' => false,
'skip_fields' => ['modified', 'created'],
]);
License
Copyright 2018 Angel S. Moreno (angelxmoreno). All rights reserved., (*10)
Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file., (*11)