jobsrey / yii2-changelog
变更日志
dev-master
2020-01-24 04:21 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-authclient: ^2.1.0
- yiisoft/yii2-bootstrap: ^2.0.0
- yiisoft/yii2-swiftmailer: ^2.0.0
Requires (Dev)
- codeception/specify: ^0.4.3
- codeception/verify: ^0.3.1
- yiisoft/yii2-codeception: ^2.0.0
This package is auto-updated.
Last update: 2024-09-24 14:42:01 UTC
README
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist jobsrey/yii2-changelog "*"
或者
"jobsrey/yii2-changelog": "*"
将以下内容添加到你的 composer.json
文件的 require 部分。
使用方法
安装扩展后,只需在你的代码中按以下方式使用它:
'components' => [ ... 'changelog' => [ 'class' => 'jobsrey\changelog\ChangeLog', ],
在模型中
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 } }
插入状态描述
- 插入
- 更新
- 删除
- 仅信息