angelxmoreno / cakephp-auditor
CakePHP的Auditor插件
1.0.2
2018-03-01 12:57 UTC
Requires
- cakephp/cakephp: ^3.4
- composer/installers: ^1.5
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0
This package is auto-updated.
Last update: 2024-09-16 03:51:39 UTC
README
需求
* CakePHP 3.4.0+
* PHP 5.6+
安装
您可以使用composer将此插件安装到您的CakePHP应用程序中。
安装composer包的推荐方式是
composer require angelxmoreno/cakephp-auditor
然后您需要应用两个行为
- 一个应用于您的UsersTable(Auditors)
$this->addBehavior('Auditor.Auditor');
- 另一个应用于您想要跟踪的表格
$this->addBehavior('Auditor.Audit');
选项
对于AuditBehavior,您有以下默认选项
[ 'attach' => true, 'reverse' => false, 'skip_fields' => [], ]
attach: 布尔值(默认true)
是否将给定的表附加到AuditsTable作为HasMany关联
reverse: 布尔值(默认false)
是否将AuditsTable附加到给定的表作为belongsTo关联
skip_fields: 数组(默认空数组)
在保存previous
和current
字段的差异时应忽略的字段。
[建议添加您的created
和modified
字段]
额外内容
我个人使用BaseTable并将所有Table类从该类扩展。这使得向所有Table类添加特质、方法和其他好东西变得更容易。我创建了一个方便的方法,当Table类不是AuditsTable时,有条件地添加Audit行为。您可以这样使用它
\Auditor\Model\Behavior\AuditBehavior::makeAuditable($this, [ 'attach' => false, 'skip_fields' => ['modified', 'created'], ]);
许可证
版权所有2018 Angel S. Moreno (angelxmoreno)。保留所有权利。
根据MIT许可证许可。必须保留包含在本存储库中的源代码中每个文件的版权声明。