Download the PHP package antonyz89/change-log-behavior without Composer
On this page you can find all versions of the php package antonyz89/change-log-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package change-log-behavior
Changelog Behavior simplified(v.1.0.0)
Simple behavior for your yii2-models
forked from Cranky4/change-log-behavior
Installation
1- Install package via composer:
2- Run migrations:
Usage
1- Add ChangeLogBehavior to any model or active record:
Attention: Behavior watches to "safe" attributes only. Add attributes into excludedAttributes if you don't want to log its changes.
2- Add ChangeLogList to view:
3- Add custom log:
Custom fields
With custom fields, you can store additional values in a property called custom_fields
. This feature is useful when you need to save values generated based on other fields or relations.
Use !
after the field's name to force it to be saved even if it hasn't changed.
How it works:
-
When finding a model, the custom field is activated to cache the current values of custom fields. Upon saving the model, the custom fields are regenerated to store both the before and after values.
-
Auto cache custom fields
- By default
$autoCache
isfalse
and the custom fields are not cached on triggerActiveRecord::EVENT_AFTER_FIND
to prevent performance issues. -
Call
cacheCustomFields()
to cache the custom fields manually. - To enable
$autoCache
set it totrue
on behaviors and the custom fields will be cached on triggerActiveRecord::EVENT_AFTER_FIND
. But be careful.
- By default
Save data on delete
By default the behavior doesn't save data on delete. Set dataOnDelete
to true
to save data on delete.
The result will be something like:
Last value is always null
.
dataOndelete = true
also save custom fields.
Parent Id
Set a parent id to change log.
This is useful to create a custom view for your changelog view.
default: null
, accept: null
| string
| callable
Example
Model Post
View post/view.php