Advertisement
fernandezekiel

Untitled

Jan 11th, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. class SoftDeleteBehavior extends CActiveRecordBehavior{
  2.     //put your code here
  3.     public $deleteColumn = 'deleted';
  4.     public $deletedByColumn = 'deletedBy';
  5.  
  6.     public function beforeDelete($event) {
  7.         $dc = $this->deleteColumn;
  8.         $dbc = $this->deletedByColumn;
  9.         if($this->owner->hasAttribute($dc))
  10.             $this->owner->$dc = 1;
  11.         if($this->owner->hasAttribute($dbc))
  12.             $this->owner->$dbc = Yii::app()->user->id;
  13.        
  14.         $this->owner->save();
  15.         /**
  16.          * $event->isValid = false is needed
  17.          * so that delete() will not be executed
  18.          */
  19.         $event->isValid = false;
  20.     // doesn't work
  21.     //return false;
  22.    
  23.         return parent::beforeDelete($event);
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement