Posted By

rahulprasad on 04/15/13


Tagged

model Yii


Versions (?)

YII Model beforeSave() action


 / Published in: PHP
 

beforeSave() function is called before a model is saved. Based on isNewRecord properly we can autosave data to some of the field(s)

  1. public function beforeSave() {
  2. if(parent::beforeSave()){
  3. if ($this->isNewRecord) {
  4. $this->creatd_on = date("Y-m-d H:i:s", time());
  5. $this->modified_on = $this->creatd_on;
  6. $this->author_id = Yum::app()->user->id;
  7. } else {
  8. $this->modified_on = date("Y-m-d H:i:s", time());
  9. }
  10.  
  11. return true;
  12. } else {
  13. return false;
  14. }
  15.  
  16. }

Report this snippet  

You need to login to post a comment.