PHPackages                             dpodium/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. dpodium/yii2-audittrail

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

dpodium/yii2-audittrail
=======================

Yii2-audittrail tracks changes to a model with behavior implementation, based on package asinfotrack/yii2-audittrail by Pascal Mueller, AS infotrack AG

02081PHP

Since Mar 6Pushed 9y ago4 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#yii2-audittrail)

Yii2-audittrail tracks changes to a model with behavior implementation.

Based on package [asinfotrack/yii2-audittrail](https://github.com/asinfotrack/yii2-audittrail) by Pascal Mueller, AS infotrack AG.

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

[](#installation)

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

Either run

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

or add

```
"dpodium/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/dpodium/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 [
    	// ...
    	'yii2-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:

```
