Difference between #4 and #5 of
How to log changes of ActiveRecords?

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:
[...]
31 1
47 followers
Viewed: 72 572 times
Version: 1.1
Category: Tutorials
Tags: Logging
Written by: pfth
Last updated by: Yang He
Created on: Feb 13, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history