Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

CakePHP 3 CreatorModifier plugin

Latest Version Software License Build Status Coverage Status Total Downloads

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.

License

MIT

Copyright

Loadsys Web Strategies 2016

About

A Cake 3 plugin that provides a Behavior to automatically set creator_id and modifier_id fields on save.

Resources

License

Packages

No packages published

Languages