Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SoftDeleteBehavior extends CActiveRecordBehavior{
- //put your code here
- public $deleteColumn = 'deleted';
- public $deletedByColumn = 'deletedBy';
- public function beforeDelete($event) {
- $dc = $this->deleteColumn;
- $dbc = $this->deletedByColumn;
- if($this->owner->hasAttribute($dc))
- $this->owner->$dc = 1;
- if($this->owner->hasAttribute($dbc))
- $this->owner->$dbc = Yii::app()->user->id;
- $this->owner->save();
- /**
- * $event->isValid = false is needed
- * so that delete() will not be executed
- */
- $event->isValid = false;
- // doesn't work
- //return false;
- return parent::beforeDelete($event);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement