Created
September 4, 2012 00:26
-
-
Save ModernTimes/3615263 to your computer and use it in GitHub Desktop.
LazySaverBehavior: prevents save() command from being executed if no attributes have 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 | |
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