dpodium / yii2-audittrail
Yii2-audittrail基于AS infotrack AG的Pascal Mueller开发的package asinfotrack/yii2-audittrail,用于跟踪具有行为实现的模型的更改。
dev-master
2017-03-06 08:00 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: 2.0.*
This package is auto-updated.
Last update: 2024-09-12 18:51:48 UTC
README
Yii2-audittrail用于跟踪具有行为实现的模型的更改。
基于由Pascal Mueller, AS infotrack AG开发的package asinfotrack/yii2-audittrail。
安装
安装此扩展的首选方式是通过composer。
运行以下命令
$ composer require dpodium/yii2-audittrail
或者将以下内容添加到您的composer.json
文件的require
部分:
"dpodium/yii2-audittrail": "dev-master"
to the require section of your composer.json file.
迁移
下载所有必要的文件后,应用迁移以创建审计跟踪条目表
yii migrate --migrationPath=@vendor/dpodium/yii2-audittrail/migrations
要删除表,只需执行相同的迁移向下操作。
用法
行为
将行为附加到您的模型,操作完成
public function behaviors() { return [ // ... 'yii2-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', ], ], // ... ]; }
小部件
小部件也非常容易使用。只需提供模型,即可获取审计跟踪。
<?= 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'], ]) ?>