Detecting changes in the model; php yii framework -
i'm creating audit trail module put in larger system; , i've created table store trail entries , "auditor" want see logged on user, page he/she in, action he/she did, , changes , when...
these want see; audit trail table looks like:
user| timestamp| module name| action| old value| new value| description
i had no problem getting user,
yii::app()->session['username']; the page/module , action getting controller's :
$this->module->getname(); $this->action->id; my problem lies changes old value new value, edits done user. sort of "sniff" out edits/ changes he/she did literally copying variables , passing through function create log.. how do dynamically?
i sort of want detect if model's properties or attributes has been changed , see changes made detail log...thanks ! sorry, i'm trying hard explain this.
in each model want observe can write afterfind() method, store current db attributes private variable, e.b. _dbvalues. in beforesave() verify current attributes ones in _dbvalues , create audit record if there change.
after have working, can take step further , create behavior it. you'd put private variable, afterfind() , beforesave() method there. can attach behavior many records.
Comments
Post a Comment