#Usage extension as behavior
Easy way:
class MyClass extends ActiveRecord {
public function behaviors(){
return [
\nhkey\arh\ActiveRecordHistoryBehavior::className(),
...
];
}
If you want use not default manager or set options for manager, you may use this construction:
class MyClass extends ActiveRecord {
public function behaviors(){
return [
'history' => [
'class' => \nhkey\arh\ActiveRecordHistoryBehavior::className(),
'manager' => 'ManagerName',
'managerOptions' => [
...
],
],
...
];
}
If you don't want to save some fields, you can use property ignoreFields (example, field "updated_at" if you use TimestampBehavior, Issue #1)
class MyClass extends ActiveRecord {
public function behaviors(){
return [
'history' => [
'class' => \nhkey\arh\ActiveRecordHistoryBehavior::className(),
'ignoreFields' => ['updated_at', 'some_other_field'],
],
...
];
}
- manager - set manager for save history in storage.
- ignoreFields - set array of fields that do not need to save in history log
- eventsList - set array of events that do need to save in history log.
##Events codes const
- BaseManager::AR_INSERT - Create new ActiveRecord-object
- BaseManager::AR_UPDATE - Update your ActiveRecord-object
- BaseManager::AR_DELETE - Remove your ActiveRecord-object
- BaseManager::AR_UPDATE_PK - Update primary key for your ActiveRecord-object
class MyClass extends ActiveRecord {
public function behaviors(){
return [
'history' => [
'class' => \nhkey\arh\ActiveRecordHistoryBehavior::className(),
'manager' => '\nhkey\arh\managers\FileManager',
'managerOptions' => [
'filePath' => '/home/logs/',
'isGenerateFilename' => true
],
],
...
];
}
or
class MyClass extends ActiveRecord {
public function behaviors(){
return [
'history' => [
'class' => \nhkey\arh\ActiveRecordHistoryBehavior::className(),
'manager' => '\nhkey\arh\managers\FileManager',
'managerOptions' => [
'filename' => '/home/user/logs_app/MyClass.log',
],
],
...
];
}
class MyClass extends ActiveRecord {
public function behaviors(){
return [
'history' => [
'class' => \nhkey\arh\ActiveRecordHistoryBehavior::className(),
'manager' => '\nhkey\arh\managers\DBManager',
'managerOptions' => [
'tableName' => 'MyLogTable',
],
],
...
];
}