cranky4/change-log-behavior
最新稳定版本:1.0.8
Composer 安装命令:
composer require cranky4/change-log-behavior
包简介
Simple changelog behavior for yii2 models
关键字:
README 文档
README
Simple behavior for your yii2-models
Installation
1- Install package via composer:
composer require cranky4/change-log-behavior "*"
2- Run migrations:
yii migrate --migrationPath=@vendor/cranky4/change-log-behavior/src/migrations
Usage
1- Add ChangeLogBehavior to any model or active record:
public function behaviors() { return [ ... [ 'class' => ChangeLogBehavior::className(), 'excludedAttributes' => ['updated_at'], ], ... ]; }
Attention: Behavior watches to "safe" attributes only. Add attributes into excludedAttributes if you don't want to log its changes.
2- Add ChangeLogList to view:
echo ChangeLogList::widget([ 'model' => $model, ])
3- Add custom log:
$model->addCustomLog('hello world!', 'hello_type')
Example
Model Post
/** * @propertu int id * @property int created_at * @property int updated_at * @property string title * @property int rating */ class Post extends yii\db\ActiveRecord { /** * @inheritdoc */ public function behaviors() { return [ [ 'class' => ChangeLogBehavior::class, 'excludedAttributes' => ['created_at','updated_at'], ] ]; } }
View post/view.php
use cranky4\ChangeLogBahavior\ListWidget as ChangeLogList; use app\models\Post; /** * @var Post $model */ echo DetailView::widget([ 'model' => $model, 'attributes' => [ 'id', 'title', 'rating', 'created_at:datetime', 'updated_at:datetime', ], ]); echo ChangeLogList::widget([ 'model' => $model, ]);
统计信息
- 总下载量: 25.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-15