PHPackages                             dbrisinajumi/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. dbrisinajumi/audittrail

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

dbrisinajumi/audittrail
=======================

A reload of the popular audit trail extension

2.1.7(10y ago)1415[1 issues](https://github.com/DBRisinajumi/audittrail/issues)[1 PRs](https://github.com/DBRisinajumi/audittrail/pulls)3BSD-2-ClausePHPPHP &gt;=5.1.0

Since Apr 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/DBRisinajumi/audittrail)[ Packagist](https://packagist.org/packages/dbrisinajumi/audittrail)[ RSS](/packages/dbrisinajumi-audittrail/feed)WikiDiscussions master Synced today

READMEChangelog (7)DependenciesVersions (17)Used By (3)

audittrail
==========

[](#audittrail)

This is basically a modification of a previous extension made by [MadSkillsTisdale](http://www.yiiframework.com/user/597/) at .

I have basically cleaned up some of the code and made a few additions to the behaviour bundled within this extension.

Installing the extension
------------------------

[](#installing-the-extension)

As such, for these reasons, the module itself has been deleted.

### Composer

[](#composer)

This extension is listed on [packagist](https://github.com/DBRisinajumi/audittrail).

```
php copmoser.phar require dbrisinajumi/audittrail

```

Require . Listed in [Packagist](http://packagist.com) or add in composer:

```
"repositories":[
        {
    	        "type": "vcs",
            	"url": "https://github.com/yiiext/fancybox-widget"
    	}
    ]

```

### Step 1

[](#step-1)

To install you must first choose a folder in which to place this repository. I have chosen:

```
/root/backend/extensions/modules
or
/vendor/dbrisinajumi

```

Since this seems most right to me. Clone this repository to that location.

### Step 2

[](#step-2)

Time to install the table. You can use the migration file provided by the original author of this extension or you can use the SQL file bundled within the migrations folder. Simply run it on your DB server (using PHPMyAdmin or something) and watch the magic unfold.

### Step 3

[](#step-3)

Create alise 'aliases' =&gt; array( 'audittrail' =&gt; 'vendor.dbrisinajumi.audittrail', )

Reference the `AuditTrail` model within your configuration:

```
'import'=>array(
	'audittrail.AuditTrail',
	'audittrail.models.*',
    	'audittrail.behaviors.*',
),

```

**Note** You can move `AuditTrail` to your `models` folder preventing you from having to link it like this.

### step 4 - Define modules

[](#step-4---define-modules)

```
        'audittrail' => array(//++
            'class' => 'vendor.dbrisinajumi.audittrail.AudittrailModule',
            'ref_models' => array(
                'DtrsTruckStatus' => array(
                    'DtrcTruckContainers' => 'dtrc_dtrs_id',
                    'D2files' => array(
                        'compare' => array(
                            'model' => 'depo2.DtrsTruckStatus',
                            'model_id' => 'pk_value',
                            ),

                    ),
                    'yii_t_category' => 'Depo2Module.model',
                    'yii_t_message' => 'Truck',
                ),
                'DtrcTruckContainers' => array(
                    'yii_t_category' => 'Depo2Module.model',
                    'yii_t_message' => 'Containers',
                ),
                'D2files' => array(
                    'hidded_fields' => ['add_datetime','user_id','model','model_id','upload_path'],
                    'yii_t_category' => 'D2filesModule.crud_static',
                    'yii_t_message' => 'Attachments'
                ),

            'ref_field_sql' => array(
                'car_id' => 'SELECT car_reg_number v FROM cars WHERE car_id = #id#',
                'price_id' => "SELECT price from prices where id = #id#",
            ),
        ),

```

- by ref\_models add for shoving in popup related table changes: \*\* 'rel\_tabel' =&gt; 'ref\_field' - add to popup changes for table rel\_table for records main\_table.id = rel\_table.ref\_field \*\* yii\_t\_category and yii\_t\_message used for displayng header for table: Yii::t('yii\_t\_category','yii\_t\_message')
- By ref\_field\_sql can define in dialog box shoving instead reference keys show it names. Select must contain column v - label of foreign key.

### Step 5

[](#step-5)

Simply use the behaviour within a model like:

```
'LoggableBehavior'=> array(
	'class' => 'audittrail.behaviors.LoggableBehavior',
)

```

### step 6

[](#step-6)

For migration in configuration file console add 'aliases' =&gt; array( 'audittrail' =&gt; 'vendor.dbrisinajumi.audittrail', ) If table name defined in params, add all params from main config 'params' =&gt; CMap::mergeArray( $mainConfig\['params'\], array(..))

### Epilogue

[](#epilogue)

If your user class is not `User` then you may (depending on your setup) need to change the relation within the `AuditLog` model to suite your needs.

API
---

[](#api)

Please note that the below snippets are snippets only and are not tested in a real environment. It is recommend that you use this section as reference and documentation only, do not copy and paste from here.

### Custom User Attributes

[](#custom-user-attributes)

Some people don't actually have defined users but do have an attribute of the auditable model that would define a unique identification of who edited it. For this end you can use:

```
'LoggableBehavior'=> array(
	'class' => 'vendor.dbrisinajumi.audittrail.behaviors.LoggableBehavior',
	'userAttribute' => 'name'
)

```

### Storing Timestamps

[](#storing-timestamps)

The date of the audit log can be changed to used timestamps instead using:

```
'LoggableBehavior'=> array(
	'class' => 'vendor.dbrisinajumi.audittrail.behaviors.LoggableBehavior',
	'storeTimestamp' => true
)

```

### Changing the date format

[](#changing-the-date-format)

You can adjust the date format using the `dateFormat` property of the behaviour:

```
'LoggableBehavior'=> array(
	'class' => 'vendor.dbrisinajumi.audittrail.behaviors.LoggableBehavior',
	'dateFormat' => 'Y-m-d H:i:s'
)

```

### Ignoring and allowing specific fields

[](#ignoring-and-allowing-specific-fields)

There is one interesting addition to this version. You can now specify an `allowed` set of fields and a `ignored` set of fields...or both.

To do this include the behaviour in your models like you normally would:

```
'LoggableBehavior'=> 'site.backend.extensions.modules.auditTrail.behaviors.LoggableBehavior'

```

But then add either an `ignored` or `allowed` (or both) list of fields to the behaviour like so:

```
'LoggableBehavior'=> array(
	'class' => 'vendor.dbrisinajumi.audittrail.behaviors.LoggableBehavior',
	'allowed' => array(
		'version',
		'ns_purchase_description'
	),
	'ignored' => array(
		'ns_purchase_description',
		'ns_display_name',
		'update_time'
	)
)

```

The names put into the `allowed` and `ignored` parameters of the behaviour represent field names.

As you will notice I allow the `ns_purchase_description` field but also ignore it. When you use the fields in this way `ignored` will replace the `allowed` and this field will be omitted.

Ignoring a whole class
----------------------

[](#ignoring-a-whole-class)

This is useful if you put the behaviour in a class that extends CActiveRecord which all your own models extend from. This is useful in cases where you want ALL your classes to share the same core (like this behaviour) without having to specify it in every model you create.

```
'LoggableBehavior'=> array(
	'class' => 'vendor.dbrisinajumi.audittrail.behaviors.LoggableBehavior',
  	'ignored_class' => array(
		'ErrorLog',  // I use this to log error messages to MYSQL, no need to keep a log of this
	),
)

```

widget audit log grid
---------------------

[](#widget-audit-log-grid)

```
$this->widget('vendor.dbrisinajumi.audittrail.components.AudittrailHistory',
        array('model'=>$model,'id' => 'audittrail_data_grid')
        );

```

link for popup
--------------

[](#link-for-popup)

```
               if(Yii::app()->user->checkAccess("audittrail")
                    && isset(Yii::app()->getModule('depo2')->options['audittrail'])
                    && Yii::app()->getModule('depo2')->options['audittrail'])
                {
                    Yii::import('audittrail.*');
                    $this->widget("vendor.dbrisinajumi.audittrail.widgets.AudittrailViewTbButton",array(
                        'model_name' => get_class($model),
                        'model_id' => $model->getPrimaryKey(),
                    ));
                }

```

Printing out the audit log
--------------------------

[](#printing-out-the-audit-log)

Since this no longer uses a module to do its work there is no global configuration for the previously inbuilt audit log to work from. Instead you can insert an audit log like (as an example only, showing an audit of changes to a book title and it's products on a book title page):

```
$model_ids = array(array($model->id, 'Title'));
foreach($model->products as $id => $product){
    $model_ids[] = array($product->id, 'Product');
}

$criteria=new CDbCriteria(array(
    'order'=>'stamp DESC',
    'with'=>array('user'),
));
$param_id = 0;
foreach( $model_ids as $id_pair ) {
    $criteria->addCondition( '( model_id = :id' . $param_id . ' AND model = :model' . $param_id . ' )', 'OR' );
    $criteria->params[ ':id' . $param_id ] = $id_pair[0];
    $criteria->params[ ':model' . $param_id ] = $id_pair[1];
    $param_id++;
}

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'title-grid',
    'dataProvider'=>new CActiveDataProvider('AuditTrail', array(
        'criteria'=>$criteria,
        'pagination'=>array(
            'pageSize'=>100,
        )
    )),
    'columns'=>array(
        array(
            'name' => 'Author',
            'value' => '$data->user ? $data->user->email : ""'
        ),
        'model',
        'model_id',
        'action',
        array(
            'name' => 'field',
            'value' => '$data->getParent()->getAttributeLabel($data->field)'
        ),
        'old_value',
        'new_value',
        array(
            'name' => 'Date Changed',
            'value' => 'date("d-m-Y H:i:s", strtotime($data->stamp))'
        )
    ),
));

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 54.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~82 days

Recently: every ~68 days

Total

13

Last Release

3795d ago

Major Versions

1.3.0 → 2.0.12015-01-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/542187ba859514d10d0952dca77df8ea889a9651b249d0b5b513da791fd2919b?d=identicon)[uldisn](/maintainers/uldisn)

---

Top Contributors

[![uldisn](https://avatars.githubusercontent.com/u/3525344?v=4)](https://github.com/uldisn "uldisn (42 commits)")[![Sammaye](https://avatars.githubusercontent.com/u/323996?v=4)](https://github.com/Sammaye "Sammaye (23 commits)")[![elenfant](https://avatars.githubusercontent.com/u/1541727?v=4)](https://github.com/elenfant "elenfant (6 commits)")[![adeg](https://avatars.githubusercontent.com/u/3998049?v=4)](https://github.com/adeg "adeg (3 commits)")[![kshamoun](https://avatars.githubusercontent.com/u/4984466?v=4)](https://github.com/kshamoun "kshamoun (1 commits)")[![ivarsju](https://avatars.githubusercontent.com/u/4513623?v=4)](https://github.com/ivarsju "ivarsju (1 commits)")[![marsuboss](https://avatars.githubusercontent.com/u/5856?v=4)](https://github.com/marsuboss "marsuboss (1 commits)")

---

Tags

Audityiitrailphundament

### Embed Badge

![Health badge](/badges/dbrisinajumi-audittrail/health.svg)

```
[![Health](https://phpackages.com/badges/dbrisinajumi-audittrail/health.svg)](https://phpackages.com/packages/dbrisinajumi-audittrail)
```

###  Alternatives

[sammaye/auditrail2

A reload of the popular audit trail extension

3318.1k4](/packages/sammaye-auditrail2)[bedezign/yii2-audit

Yii2 Audit records and displays web/cli requests, database changes, php/js errors and associated data.

201657.4k4](/packages/bedezign-yii2-audit)[sammaye/yii2-audittrail

A port of audit trail

39408.2k](/packages/sammaye-yii2-audittrail)[samdark/yii2-psr-log-target

Yii 2 log target which uses PSR-3 compatible logger

841.8M10](/packages/samdark-yii2-psr-log-target)[cornernote/yii-audit-module

Track and store usage information including page requests, database field changes and system errors.

226.6k](/packages/cornernote-yii-audit-module)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
