yii2mod / yii2-data-sync-behavior
此包已被废弃,不再维护。未建议替代包。
用于将数据库表中的数据导出到本地文件的行为。更改使用模型事件进行跟踪。
1.3
2016-11-22 14:43 UTC
Requires
- php: >=5.5
- yiisoft/yii2: >=2.0.8
Requires (Dev)
This package is not auto-updated.
Last update: 2017-08-20 08:17:09 UTC
README
用于将数据库表中的数据导出到本地文件的行为。更改使用模型事件进行跟踪。
[](https://packagist.org.cn/packages /yii2mod/yii2-data-sync-behavior)
安装
通过 composer 安装此扩展是首选方式。
运行以下命令:
php composer.phar require --prefer-dist yii2mod/yii2-data-sync-behavior "*"
或者将以下内容添加到您的 composer.json
文件的 require 部分中:
"yii2mod/yii2-data-sync-behavior": "*"
添加
记录更改
将行为附加到模型上
use yii2mod\datasync\DataSyncBehavior; public function behaviors() { return [ 'dataSync' => [ 'class' => DataSyncBehavior::className(), // `folderPath` property maybe need to change. 'folderPath' => '@app/config/data' ], ]; }
- 在模型事件(AFTER_UPDATE, AFTER_INSERT, AFTER_DELETE)之后,行为将自动在默认路径(@app/config/data)中创建文件,其中包含此模型的数据。
- 文件将以 json 格式创建。
导入更改
- 将
datasync
命令添加到控制台配置
'controllerMap' => [
'datasync' => [
'class' => 'yii2mod\datasync\commands\DataSyncCommand',
// `folderPath` property maybe need to change.
'folderPath' => '@app/config/data'
],
],
-
从控制台执行命令。例如:
php yii datasync - synchronize data for all files php yii datasync/index --table=User - synchronize data only for `User` table