loadsys / cakephp-creatormodifier
CakePHP 3.x Plugin to set Creator and Modifier automagic fields during save.
Installs: 13 863
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 9
Forks: 3
Open Issues: 5
Type:cakephp-plugin
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
Requires (Dev)
- loadsys/loadsys_codesniffer: ~3.0
- phpunit/phpunit: ~4.7
- satooshi/php-coveralls: ~2.0
This package is not auto-updated.
Last update: 2024-10-26 18:38:47 UTC
README
Sets a creator_id
and modifier_id
on records during save using the logged in User.id field. Operates almost identically to the core's Timestamp behavior.
Requirements
- PHP 5.4.16+
- CakePHP 3.0+
Installation
Composer
$ composer require loadsys/cakephp-creatormodifier:~1.0
In your config/bootstrap.php
file, add:
Plugin::load('CreatorModifier', ['bootstrap' => false, 'routes' => false]);
OR
bin/cake plugin load CreatorModifier
Usage
- Add this plugin for use in an Table, by adding this line to your Table's
initialize()
method.
$this->addBehavior('CreatorModifier.CreatorModifier');
- Or to customize the behavior
$this->addBehavior('CreatorModifier.CreatorModifier', [ 'events' => [ 'Model.beforeSave' => [ // Field storing the User.id who created the record, // only triggers on beforeSave when the Entity is new. 'user_who_created_me_id' => 'new', // Field storing the User.id who modified the record, // always triggers on beforeSave. 'user_who_modified_me_id' => 'always' ] ], // The key to read from `\Cake\Network\Request->session()->read();` // to obtain the User.id value to set during saves. 'sessionUserIdKey' => 'Auth.User.id', ]);
Contributing
Code of Conduct
This project has adopted the Contributor Covenant as its code of conduct. All contributors are expected to adhere to this code. Translations are available.
Reporting Issues
Please use GitHub Isuses for listing any known defects or issues.
Development
When developing this plugin, please fork and issue a PR for any new development.
Set up a working copy:
$ git clone git@github.com:YOUR_USERNAME/CakePHP-CreatorModifier.git
$ cd CakePHP-CreatorModifier/
$ composer install
$ vendor/bin/phpcs --config-set installed_paths vendor/loadsys/loadsys_codesniffer,vendor/cakephp/cakephp-codesniffer
Make your changes:
$ git checkout -b your-topic-branch
# (Make your changes. Write some tests.)
$ vendor/bin/phpunit
$ vendor/bin/phpcs -p --extensions=php --standard=Loadsys ./src ./tests
Then commit and push your changes to your fork, and open a pull request.