loadsys/cakephp-creatormodifier

CakePHP 3.x 插件,用于在保存时自动设置 Creator 和 Modifier 字段。

安装量: 13,856

依赖者: 0

建议者: 0

安全性: 0

星标: 5

关注者: 9

分支: 3

开放问题: 5

类型:cakephp-plugin

1.0.4 2018-08-14 18:34 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:14:59 UTC


README

Latest Version Software License Build Status Coverage Status Total Downloads

在保存记录时,使用已登录用户 id 字段设置 creator_idmodifier_id。其操作与核心的 Timestamp 行为 几乎相同。

要求

  • PHP 5.4.16+
  • CakePHP 3.0+

安装

Composer

$ composer require loadsys/cakephp-creatormodifier:~1.0

在您的 config/bootstrap.php 文件中,添加

Plugin::load('CreatorModifier', ['bootstrap' => false, 'routes' => false]);

或者

bin/cake plugin load CreatorModifier

用法

  • 通过在表的 initialize() 方法中添加此行来添加此插件以用于表。
$this->addBehavior('CreatorModifier.CreatorModifier');
  • 或者自定义行为
$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',
]);

贡献

行为准则

本项目采用了贡献者公约作为其 行为准则。所有贡献者都应遵守此准则。 有可用的翻译

报告问题

请使用 GitHub Issues 来列出任何已知的缺陷或问题。

开发

在开发此插件时,请进行分支并提交 PR 以进行任何新开发。

设置工作副本

$ 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

进行更改

$ 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

然后提交并推送您的更改到您的分支,并打开一个拉取请求。

许可证

MIT

版权

Loadsys Web Strategies 2016