Coder Social home page Coder Social logo

motionland / yii2-audittrail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from asinfotrack/yii2-audittrail

0.0 2.0 0.0 151 KB

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

License: MIT License

PHP 100.00%

yii2-audittrail's Introduction

Yii2-audittrail

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

Advantages

This is not the first audit trail extension. So why use this one? Those are some of the major advantages:

  • this extension works with composite primary keys
  • it also works with console applications
  • you can explicitly configure what fields to log
  • GridView-baded widget to show the audit trail with huge customization options (eg rendering of values by closures, yii-formatter, etc.)

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require asinfotrack/yii2-audittrail

or add

"asinfotrack/yii2-audittrail": "dev-master"

to the require section of your composer.json file.

Migration

After downloading everything you need to apply the migration creating the audit trail entry table:

yii migrate --migrationPath=@vendor/asinfotrack/yii2-audittrail/migrations

To remove the table just do the same migration downwards.

Usage

Behavior

Attach the behavior to your model and you're done:

public function behaviors()
{
    return [
    	// ...
    	'audittrail'=>[
    		'class'=>AuditTrailBehavior::className(),
    		
    		// some of the optional configurations
    		'ignoredAttributes'=>['created_at','updated_at'],
    		'consoleUserId'=>1, 
			'attributeOutput'=>[
				'desktop_id'=>function ($value) {
					$model = Desktop::findOne($value);
					return sprintf('%s %s', $model->manufacturer, $model->device_name);
				},
				'last_checked'=>'datetime',
			],
    	],
    	// ...
    ];
}

Widget

The widget is also very easy to use. Just provide the model to get the audit trail for:

<?= AuditTrail::widget([
	'model'=>$model,
	
	// some of the optional configurations
	'userIdCallback'=>function ($userId, $model) {
 		return User::findOne($userId)->fullname;
	},
	'changeTypeCallback'=>function ($type, $model) {
		return Html::tag('span', strtoupper($type), ['class'=>'label label-info']);
	},
	'dataTableOptions'=>['class'=>'table table-condensed table-bordered'],
]) ?>

yii2-audittrail's People

Contributors

pasci84 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.