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.
- PHP 5.4.16+
- CakePHP 3.0+
$ composer require loadsys/cakephp-creatormodifier:~1.0In your config/bootstrap.php file, add:
Plugin::load('CreatorModifier', ['bootstrap' => false, 'routes' => false]);OR
bin/cake plugin load CreatorModifier- 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',
]);This project has adopted the Contributor Covenant as its code of conduct. All contributors are expected to adhere to this code. Translations are available.
Please use GitHub Isuses for listing any known defects or issues.
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-codesnifferMake 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 ./testsThen commit and push your changes to your fork, and open a pull request.