Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LazySaverBehavior: prevents save() command from being executed if no attributes have changed
<?php
Yii::import('ext.AttributesBackupBehavior');
/**
* Prevent save() command from being executed if no attributes have changed
* The AttributesBackupBehavior class is available here:
* http://www.yiiframework.com/extension/attributesbackupbehavior/
*/
class LazySaverBehavior extends AttributesBackupBehavior {
/**
* Prevent save() command from being executed if no attributes have changed
* @param CModelEvent $event
*/
public function beforeSave($event) {
$owner = $this->getOwner();
if(!$owner->getIsNewRecord() && !$this->attributesChanged()) {
$event->isValid = false;
}
parent::beforeSave($event);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment