PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Uldis Nelsons   D3 PHP Record Audit Trail   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: D3 PHP Record Audit Trail
Keep track of changes to model object data values
Author: By
Last change:
Date: 4 years ago
Size: 2,182 bytes
 

Contents

Class file image Download

Total Downloads

Display audittrail data

Add migrations paths

    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => [
                '@vendor/sammaye/yii2-audittrail/migrations',
                '@vendor/d3yii2/d3audittrail/migrations',

            ],
        ],
    ],

Define module in console and web

    'modules' => [

        'd3audittrail' => [
            'class' => 'd3yii2\d3audittrail\Module',
        ],
    ]    

define in parameters table name

    'params' => [
        'audittrail.table' => 'tbl_audit_trail'
    ]    

Add to model behaviors


    public function behaviors(): array
    {
        return ArrayHelper::merge(
            parent::behaviors(),
            [
                'sammaye\audittrail\LoggableBehavior'
            ]
        );
    }

Define model label

class Model extends extends \yii\db\ActiveRecord
    /
    * model label 
    */
    public function tableLabel(): string
    {
        return 'Data Record';
    }

    public static function audittrailHiddedFields()
    {
        return [
            'password'
        ];
    }

    public static function audittrailSqlFields()
    {
        return [
            'client_id' => 'select name from client where id=:id'
        ];
    }

    public static function audittrailRefModels()
    {
        return [
            [
                'model' => TblAuditTrail::class,
                'ref_field' => 'my_id',
                'hidded_fields' => ['a','b'],
                'field_sql' => [
                    'field1' => 'select name from user where id=:id'
                 ]               
            ]           
        ];
    }
}

Add to view button

    $this->addPageButtons(AuditTrailButton::widget([
                'modelName' => coalmar\delivery\models\CmdDelivery::className(),
                'modelId' => $model->id
    ]));