Download the PHP package insolita/yii2-arsync without Composer
On this page you can find all versions of the php package insolita/yii2-arsync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download insolita/yii2-arsync
More information about insolita/yii2-arsync
Files in insolita/yii2-arsync
Package yii2-arsync
Short Description This behavior for automatic or manual sync data between two models, without declaration relation. This behavior must be attached on master model. Main purposes - for sync rarely modified data from more reliable database storage to redis storage for frequently access; Support actual data state in some development cases;
License MIT
Informations about the package yii2-arsync
ActiveRecord Synchronization Behavior
This behavior for automatic or manual sync data between two models, without declaration relation. This behavior must be attached on master model. Main purposes - for sync rarely modified data from more reliable database storage to redis storage for frequently access; Support actual data state in some development cases;
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by : See more in code
public function behaviors(){
return [
'ArSyncBehavior'=>[
'class' => ArSyncBehavior::class,
'slaveModel' => \your\model\namespase\Slave::className(),
'slaveScenario'=>'sync',
'errorSaveCallback'=>function($slave){
Yii::error(VarDumper::export($slave->errors));
throw new InvalidConfigException('fail save ');
},
'errorDeleteCallback'=>function($slave){
Yii::error('fail delete '.$slave->getPrimaryKey());
},
'fieldMap' => [
'id'=>'id',
'title' => 'name',
'foo' => 'foo',
'bar' => 'bar',
'baz' => function($master)
{
return $master->baz * 2;
},
],
]
];
}