PHPackages                             sammaye/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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. sammaye/yii2-audittrail

ActiveYii2-extension[Logging &amp; Monitoring](/categories/logging)

sammaye/yii2-audittrail
=======================

A port of audit trail

1.3.0(6y ago)39408.2k—7.6%29[1 issues](https://github.com/Sammaye/yii2-audittrail/issues)BSD-3-ClausePHP

Since Feb 24Pushed 5y ago12 watchersCompare

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

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

yii2-audittrail
===============

[](#yii2-audittrail)

Yii2 edition of the [audittrail extension](https://github.com/Sammaye/audittrail).

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

[](#installation)

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

```
php composer.phar require sammaye/yii2-audittrail

```

### Migration

[](#migration)

There are two ways of doing this:

- Copy the migration file (within the `migrations` folder) to your `console/migrations` folder
- Run `php yii migrate --migrationPath=@vendor/sammaye/yii2-audittrail/migrations`

How to use
----------

[](#how-to-use)

To use this extension you can simply add it to the model's behaviours:

```
use yii\db\ActiveRecord;

class Model extends ActiveRecord
{
    public function behaviors()
    {
        return [
            'sammaye\audittrail\LoggableBehavior'
        ];
    }
}
```

You can convert the entered behaviour into a key - value structure to define options for the extension for that model:

```
class Model extends ActiveRecord
{
    public function behaviors()
    {
        return [
            'LoggableBehavior' => [
                'class' => 'sammaye\audittrail\LoggableBehavior',
                'ignored' => ['some_field'], // This ignores fields from a selection of all fields, not needed with allowed
                'allowed' => ['another_field'] // optional, not needed if you use ignore
            ]
        ];
    }
}
```

And that is basically how to setup this extension.

Changes
-------

[](#changes)

There are a couple of changes.

One of them is how to define global parameters for this extension.

An example of global parameters would be setting you own table name or defining the location of the user model.

To define your own table you can add a parameter to your `params.php` file called `audittrail.table` which would take something like `{{%audit}}`.

To define your own user model location you can add `audittrail.model` using a value like `common\models\User`.

The only other change is really to do with the best way to query the audit trail.

The below example is the one from the previous documentation rewritten for Yii2:

```
