加载中...

Yii-数据模型-beforeSave保存数据前自动处理


  1. protected function beforeSave()
  2. {
  3. if(parent::beforeSave()){
  4. if($this->isNewRecord){
  5. $this->create_time = date('y-m-d H:m:s');
  6. $this->create_user_id = Yii::app()->user->id;
  7. $this->status_id = '0';
  8. }else{
  9. $this->update_time = date('y-m-d H:m:s');
  10. $this->update_user_id = Yii::app()->user->id;
  11. }
  12. return true;
  13. }else{
  14. return false;
  15. }
  16. }


还没有评论.