\User\Model\BehaviorWhoDidItBehavior

WhoDidIt Behavior.

Handles "created_by", "modified_by" fields for a given table. It's similar to the "created", "modified" automagic, but it stores the logged User's ID.

This is useful to track who created records, and the last user that has changed them.

Summary

Methods
Properties
Constants
__construct()
beforeSave()
No public properties found
No constants found
_getUserId()
$_table
$_defaultConfig
N/A
No private methods found
No private properties found
N/A

Properties

$_table

$_table : \Cake\ORM\Table

Table which this behavior is attached to.

Type

\Cake\ORM\Table

$_defaultConfig

$_defaultConfig : array

Default configuration.

  • idCallable: It can be either a callable method that should return logged User's ID or a string representing a session key from where to read the ID. By Defaults it's set yo Auth.id for reading from Auth's session.

  • createdByField: The name of the "created_by" field in DB. Defaults to created_by.

  • modifiedByField: The name of the "modified_by" field in DB. Default to modified_by.

  • userModel: The name of the Users class table, used to bind user's information to the table being managed by this behavior. Defaults to User.Users

  • autoBind: Automatically bind the table to the User table. (default true)

Type

array

Methods

__construct()

__construct(\Cake\ORM\Table $table, array $config)

Constructor.

Parameters

\Cake\ORM\Table $table

The table this behavior is attached to

array $config

Configuration array for this behavior

beforeSave()

beforeSave(\Cake\Event\Event $event, \Cake\ORM\Entity $entity, array $options) : boolean

Run before a model is saved.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Cake\ORM\Entity $entity

The entity being saved

array $options

Array of options for the save operation

Returns

boolean —

True if save should proceed, false otherwise

_getUserId()

_getUserId() : integer

Gets current User's ID.

Returns

integer —

User ID, zero if not found