PHP code example of illusiard / auditlog

1. Go to this page and download the library: Download illusiard/auditlog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

illusiard / auditlog example snippets


use illusiard\auditlog\components\AuditLogger;

[
    'components' => [
        'auditlog' => [
            'class' => AuditLogger::class,
            'userClass' => app\models\User::class,
        ]
    ],
]

use illusiard\auditlog\components\AuditBehavior;

class Order extends ActiveRecord
{
    public function behaviors(): array
    {
        return [
            'audit' => [
                'class' => AuditBehavior::class,
                'entityTypeCode' => 'order',
            ],
        ];
    }
}

'context' => function () {
    return [
        'route' => Yii::$app->requestedRoute,
        'ip' => Yii::$app->request->userIP,
        'userAgent' => Yii::$app->request->userAgent,
    ];
},

use illusiard\auditlog\components\AuditLogger;

AuditLogger::getInstance()->log(
    entityTypeCode: 'order',
    entityId: 42,
    actionCode: 'publish',
    diff: null,
    context: ['reason' => 'manual publish']
);
bash
php yii migrate --migrationPath=@illusiard/auditlog/migrations