cornernote / yii-audit-module

Track and display usage information including page requests, database field changes, php errors and yii logs.
https://cornernote.github.io/yii-audit-module
Other
22 stars 13 forks source link

Save specific model attributes #30

Closed RuneSP closed 9 years ago

RuneSP commented 9 years ago

I have the audit module up and running and its working great.

However I would like to be able to specify which attributes (or fields) of each model that should be tracked. For instance I have a model with a lot of attributes that are often changed, but I'm only interested in tracking the value of the "status" property. Is this possible?

cornernote commented 9 years ago

Hi @RuneSP,

Yes, you can use ignoreFields:

https://github.com/cornernote/yii-audit-module/blob/master/audit/components/AuditFieldBehavior.php#L64

class Post extends CActiveRecord
{
    public function behaviors()
    {
        return array(
            'AuditFieldBehavior' => array(
                'insert' => array('modified', 'modified_by', 'deleted', 'deleted_by'),
                'update' => array('created', 'created_by', 'modified'),
            ),
        );
    }
}
cornernote commented 9 years ago

Sorry, should be like this

class Post extends CActiveRecord
{
    public function behaviors()
    {
        return array(
            'AuditFieldBehavior' => array(
                'class' => 'audit.components.AuditFieldBehavior',
                'ignoreFields' => array(
                    'insert' => array('modified', 'modified_by', 'deleted', 'deleted_by'),
                    'update' => array('created', 'created_by', 'modified'),
                ),
            ),
        );
    }
}