How to log changes of ActiveRecords?

Comparing #4 with #5

Revision #5 was created by pfth pfth on Feb 13, 2009, 12:41:27 PM.

Added PHP code format

Content

[...]
crud ActiveRecordLog

To be able to log the changes we will use a behavior class. So you have to create one (i.e. ActiveRecordLogableBehavior) and store it somewhere in your application directory (i.e. \protected\behaviors). The behavior class should extend [CActiveRecordBehavior] as we want to work with ActiveRecords here.

     
```php 
class ActiveRecordLogableBehavior extends CActiveRecordBehavior
{
private $_oldattributes = array();
[...]
$this->_oldattributes=$value;
}
}
 
```


The behavior class uses the ActiveRecordLog Model to store the log lines into the database. It will log a line each time a record is inserted or deleted. It will also log a line for each field which is changed.

In order to make an ActiveRecord Model use this behavior, you have to add the following code to the Model class:
[...]