2012-05-18 36 views
0

我不知道這個函數會返回什麼,只是修改記錄屬性或其他的東西?這個函數返回什麼return parent :: beforeSave();?

protected function beforeSave() 
{ 
    if ($this->getIsNewRecord()) 
    { 
     $this->created = Yii::app()->localtime->UTCNow; 
    }    
    $this->lastmodified = Yii::app()->localtime->UTCNow; 

    if ($this->dob == '') { 
     $this->setAttribute('dob', null); 
    } else { 
     $this->dob=date('Y-m-d', strtotime($this->dob)); 
    } 
    if($this->image!="") 
    { 
     $this->imgfile_name = $this->image->name; 
     $this->imgfile_type = $this->image->type; 
     $this->imgfile_size = $this->image->size; 
    } 
    $this->phone=substr($this->phone,0,3).substr($this->phone,4,3).substr($this->phone,8,4); 

    return parent::beforeSave(); 
} 

回答

1

CActiveRecord::beforeSave應該返回true如果模型處於有效狀態,並且可以保存,並false如果它不是。

+0

你需要最後一行,這樣beforeSave()的父實現也可以觸發 – Narretz