rmrevin / yii2-changelog
Active record changelog extension for Yii 2 framework
Installs: 290
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 4
Forks: 4
Open Issues: 3
Type:yii2-extension
Requires
- php: >=5.4.0
- yiisoft/yii2: 2.0.*
Requires (Dev)
- yiisoft/yii2-debug: 2.0.*
This package is not auto-updated.
Last update: 2024-12-21 19:31:57 UTC
README
This extension provides a changelog functional.
For license information check the LICENSE-file.
Support
Installation
The preferred way to install this extension is through composer.
Either run
composer require "rmrevin/yii2-changelog:~1.0"
or add
"rmrevin/yii2-changelog": "~1.0",
to the require
section of your composer.json
file.
Execute migrations:
php yii migrate --migrationPath=@rmrevin/yii/changelog/migrations
Usage
To view the history, you can use a special panel for debug. Or make your own section to view the data in your administration panel.
To enable the debug panel, add the following code in the module configuration debug.
'modules' => [ // ... 'debug' => [ 'class' => yii\debug\Module::className(), 'panels' => [ rmrevin\yii\changelog\debug\panels\ChangelogPanel::class, ], ], ],
For ActiveRecord
models for which you want to track changes,
you must implement the interface rmrevin\yii\changelog\interfaces\LoggableInterface
and add the behavior of rmrevin\yii\changelog\behaviors\ChangelogBehavior
.
Example:
<?php use rmrevin\yii\changelog\interfaces\LoggableInterface; use rmrevin\yii\changelog\behaviors\ChangelogBehavior; use yii\db\ActiveRecord; /** * Class ShopItem * * @property integer $id * @property integer $number * @property string $title * @property integer $created_at * @property integer $updated_at * @property integer $synchronized_at */ class ShopItem extends ActiveRecord implements LoggableInterface { /** * @inheritdoc */ public function __toString() { return sprintf('[%s] %s', $this->number, $this->title); } /** * @inheritdoc */ public function behaviors() { return [ // ... [ 'class' => ChangelogBehavior::class, 'ignoreAttributes' => [ // these attributes are not tracked 'updated_at', 'synchronized_at', ], ], ]; } }
Done
Now when you try to create, modify or delete an instance of a model ShopItem
in the table {{%changelog}}
will be recorded relevant information.