jobsrey/yii2-changelog

Change Log

Installs: 15

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Open Issues: 1

Type:yii2-extension

dev-master 2020-01-24 04:21 UTC

This package is auto-updated.

Last update: 2024-09-24 14:42:01 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist jobsrey/yii2-changelog "*"

or add

"jobsrey/yii2-changelog": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

'components' => [
        ...
        'changelog' => [
            'class' => 'jobsrey\changelog\ChangeLog',
        ],

on model

class Users extends \yii\db\ActiveRecord
{

    public $old_attr; //old atribute


    ...

    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);

        if($insert){ //save log insert            
            Yii::$app->changelog->saveLogMessage($this, $this->username.' telah dibuat!',1);
        } else { //save log update
            foreach($changedAttributes as $attr => $value){
                Yii::$app->changelog->saveLogUpdateByOne($attr,$this,$this->old_attr);
            }
        }

        return true;
    }

    public function afterFind(){

        parent::afterFind();
        
        $this->old_attr = $this->getAttributes(); //add to compare data
    }

}

keterangan status

  1. insert
  2. update
  3. delete
  4. only info