1. Go to this page and download the library: Download faustvik/yii2-audit-log 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/ */
faustvik / yii2-audit-log example snippets
use FaustVik\AuditLog\Yii2\Integration\AuditLogBehavior;
class User extends ActiveRecord
{
public function behaviors(): array
{
return [
'auditLog' => [
'class' => AuditLogBehavior::class,
'excludeAttributes' => ['hash_password', 'auth_key'],
],
];
}
}
use FaustVik\AuditLog\Core\Query\AuditLogQuery;
use FaustVik\AuditLog\Core\Contracts\AuditStorageInterface;
$storage = Yii::createObject(AuditStorageInterface::class);
// All changes for a specific User record
$logs = (new AuditLogQuery($storage))
->forEntityClass(User::class)
->forEntityId($userId)
->operation(\FaustVik\AuditLog\Core\Enums\Operation::Update)
->dateRange('2025-01-01', '2025-12-31')
->limit(50)
->all();
// All changes across all User records today (no specific ID
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.