Installation and Configuration

Download

Download using composer by running the following command:

$ composer require --prefer-dist bedezign/yii2-audit:"^1.0"

Or add a require line to your composer.json:

{
    "require": {
        "bedezign/yii2-audit": "^1.0"
    }
}

Migrations

Run the migrations from the migrations folder to create the relevant tables:

$ php yii migrate --migrationPath=@bedezign/yii2/audit/migrations

Upgrading from pre 1.0? Be sure to read this.

Module Configuration

Add Audit to your configuration array:

<?php
$config = [
    'modules' => [
        'audit' => 'bedezign\yii2\audit\Audit',
    ],
];

See Module Configuration for the all configuration options and advanced usage information.

Logging Database Changes

Add AuditTrailBehavior to the models you want to log:

<?php
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            'bedezign\yii2\audit\AuditTrailBehavior'
        ];
    }
}

See Trail Panel for the all configuration options and advanced usage information.

Logging Javascript

Register JSLoggingAsset in any of your views:

<?php
\bedezign\yii2\audit\web\JSLoggingAsset::register($this);

See Javascript Panel for the all configuration options and advanced usage information.

Logging Errors

Add ErrorHandler to your configuration array:

<?php
$config = [
    'components' => [
        'errorHandler' => [
            // web error handler
            'class' => '\bedezign\yii2\audit\components\web\ErrorHandler',
            // console error handler
            //'class' => '\bedezign\yii2\audit\components\console\ErrorHandler',
        ],
    ],
];

Important: Be sure to use the correct error handler! Don’t simply add it to the common configuration, but instead add it in the frontend/web and console configuration separately.

See Error Panel for the all configuration options and advanced usage information.

Viewing the Audit Data

Assuming you named the module “audit” you can then access the audit module through the following URL:

http://localhost/path/to/index.php?r=audit

Where to now ?

Check out the other Documentation