Created
January 5, 2012 14:51
-
-
Save davialexandre/1565566 to your computer and use it in GitHub Desktop.
A simple behavior to store the original loaded activerecord values and use it to check if any was changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AttributesBackupBehavior extends CActiveRecordBehavior { | |
private $old_attributes; | |
public function afterFind($event) { | |
parent::afterFind($event); | |
foreach($this->owner->attributes as $name => $value) { | |
$this->old_attributes[$name] = $value; | |
} | |
} | |
public function attributesChanged() { | |
$changed_attributes = array_diff($this->owner->attributes, $this->old_attributes); | |
return !empty($changed_attributes); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment