PHPackages                             ua0leg/yii2-action-log - 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. ua0leg/yii2-action-log

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

ua0leg/yii2-action-log
======================

Yii2 action log for ActiveRecord create/update/delete with admin UI and revert

v1.0.0(today)01↑2900%MITPHPPHP &gt;=8.2

Since Jun 26Pushed todayCompare

[ Source](https://github.com/ua0leg/yii2-action-log)[ Packagist](https://packagist.org/packages/ua0leg/yii2-action-log)[ RSS](/packages/ua0leg-yii2-action-log/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

yii2-action-log
===============

[](#yii2-action-log)

Yii2 extension that logs ActiveRecord **create**, **update**, and **delete** actions, stores before/after snapshots, and provides an admin UI with statistics and one-click revert.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Yii2 ~2.0.45
- MySQL/MariaDB (uses `enum` column type in migration)

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

[](#installation)

### Step 1 — Install via Composer

[](#step-1--install-via-composer)

From your Yii2 application root:

```
composer require ua0leg/yii2-action-log
```

If the package is not on Packagist yet, add a VCS repository to your app's `composer.json` first:

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/ua0leg/yii2-action-log.git"
        }
    ],
    "require": {
        "ua0leg/yii2-action-log": "^1.0"
    }
}
```

Then run `composer update ua0leg/yii2-action-log`.

For local development (same machine, symlinked):

```
{
    "repositories": [
        {
            "type": "path",
            "url": "../yii2-action-log",
            "options": { "symlink": true }
        }
    ],
    "require": {
        "ua0leg/yii2-action-log": "@dev"
    }
}
```

### Step 2 — Register the module

[](#step-2--register-the-module)

Add the module to `config/web.php`:

```
'modules' => [
    'action-log' => [
        'class' => \Ua0leg\Yii2ActionLog\Module::class,
        'userModelClass' => \app\models\User::class,
        'modelNamespaces' => ['app\\models\\'],
    ],
],
```

OptionDescriptionDefault`userModelClass`Your user AR class (used for labels and relations)`null``modelNamespaces`Prefixes to resolve logged table names to AR classes`['app\\models\\']``excludedUserIds`User IDs hidden from list/stat queries`[]``pageSize`Grid page size on the index page`100`### Step 3 — Run migrations

[](#step-3--run-migrations)

Run:

```
php yii migrate --migrationPath=@vendor/ua0leg/yii2-action-log/src/migrations
```

This creates the `action_log` table.

### Step 4 — Restrict access to the admin UI

[](#step-4--restrict-access-to-the-admin-ui)

The module does not enforce RBAC by itself. Add access rules in your app config, for example:

```
'modules' => [
    'action-log' => [
        'class' => \Ua0leg\Yii2ActionLog\Module::class,
        'userModelClass' => \app\models\User::class,
        'as access' => [
            'class' => \yii\filters\AccessControl::class,
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['admin'],
                ],
            ],
        ],
    ],
],
```

Adjust `roles` to match your app's authorization.

### Step 5 — Open the admin UI

[](#step-5--open-the-admin-ui)

After configuration, visit:

- **Log list:** `/action-log`
- **Statistics:** `/action-log/default/stat`

Route prefix follows your module id (`action-log` in the examples above).

---

Logging model changes
---------------------

[](#logging-model-changes)

### Option A — Extend `LoggableActiveRecord` (recommended)

[](#option-a--extend-loggableactiverecord-recommended)

Your table must include: `created_at`, `updated_at`, `created_by`, `updated_by`.

```
