PHPackages                             asinfotrack/yii2-audittrail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. asinfotrack/yii2-audittrail

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

asinfotrack/yii2-audittrail
===========================

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

1.0.3(3y ago)1727.0k14[1 PRs](https://github.com/asinfotrack/yii2-audittrail/pulls)MITPHPPHP &gt;=7.1.0

Since Jan 26Pushed 3y ago9 watchersCompare

[ Source](https://github.com/asinfotrack/yii2-audittrail)[ Packagist](https://packagist.org/packages/asinfotrack/yii2-audittrail)[ RSS](/packages/asinfotrack-yii2-audittrail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (11)Used By (0)

Yii2-audittrail
===============

[](#yii2-audittrail)

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

Advantages
----------

[](#advantages)

This is not the first audit trail extension. So why use this one? Those are some of the major advantages:

- this extension works with composite primary keys
- it also works with console applications
- you can explicitly configure what fields to log
- GridView-baded widget to show the audit trail with huge customization options (eg rendering of values by closures, yii-formatter, etc.)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require asinfotrack/yii2-audittrail
```

or add

```
"asinfotrack/yii2-audittrail": "dev-master"

```

to the `require` section of your `composer.json` file.

Migration
---------

[](#migration)

After downloading everything you need to apply the migration creating the audit trail entry table:

```
yii migrate --migrationPath=@vendor/asinfotrack/yii2-audittrail/migrations

```

To remove the table just do the same migration downwards.

Usage
-----

[](#usage)

#### Behavior

[](#behavior)

Attach the behavior to your model and you're done:

```
public function behaviors()
{
    return [
    	// ...
    	'audittrail'=>[
    		'class'=>AuditTrailBehavior::className(),

    		// some of the optional configurations
    		'ignoredAttributes'=>['created_at','updated_at'],
    		'consoleUserId'=>1,
			'attributeOutput'=>[
				'desktop_id'=>function ($value) {
					$model = Desktop::findOne($value);
					return sprintf('%s %s', $model->manufacturer, $model->device_name);
				},
				'last_checked'=>'datetime',
			],
    	],
    	// ...
    ];
}
```

### Widget

[](#widget)

The widget is also very easy to use. Just provide the model to get the audit trail for:

```
