sateler / yii2-changelog
Yii2 behavior for storing model/table changelogs
Installs: 1 485
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 1
Type:yii2-extension
Requires
- kartik-v/yii2-date-range: ^1.6.8
- ramsey/uuid: ^4.0
- yii2tech/csv-grid: ^1.0
- yiisoft/yii2: ^2.0.10
README
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist sateler/yii2-changelog "^1.0"
or add
"sateler/yii2-changelog": "^1.0"
to the require section of your composer.json
file.
Once the extension is installed, add namespace to console config and run the required migration:
return [ 'controllerMap' => [ 'migrate' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationNamespaces' => [ 'sateler\changelog\migrations', ], ], ], ];
./yii2 migrate
Usage
Once installed, enable changelog for selected models by adding the following config to the model:
public function behaviors() { return [ [ 'class' => \sateler\changelog\ChangeLogBehavior::className(), 'ignore' => [], // ignore changes on listed columns ], ... ]; }
You can review the model changelog at http://hostname/changelog/
, or you can code your own controller
by using sateler\changelog\models\Changelog
.
If you want to 'see' the changelogs, add the following configuration and go to http://hostname/changelog/
:
return [ 'controllerMap' => [ 'changelog' => [ 'class' => 'sateler\changelog\controllers\ChangelogController', 'viewPath' => '@vendor/sateler/yii2-changelog/views/changelog', // Optional: if set, it's used in the views to create the html link for the record. 'urlCreator' => function ($table_name, $row_id) { $table_name = \yii\helpers\Html::encode(str_replace('_', '-', $table_name)); return yii\helpers\Url::to(["$table_name/view", 'id' => $row_id]); }, ] ], ];
Or you can code your own controller by using the sateler\changelog\models\Changelog
model.