Revision #5 has been created by pfth on Feb 13, 2009, 12:41:27 PM with the memo:
Added PHP code format
« previous (#4) next (#6) »
Changes
Title
unchanged
How to log changes of ActiveRecords?
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
Content
changed
[...]
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:[...]