doumi4676 2014-07-30 10:40
浏览 127

如何在Yii框架中编辑自动生成的模型?

protected function beforeSave()
{
  if(parent::beforeSave())
  {
     if($this->isNewRecord)
     {
        $this->create_time = $this->update_time=time();
        $this->author_id = Yii::app()->user->id;
     }
     else
        $this->update_time = time();
     return true;
 }
 else
    return false;

}

Above is a sample code of model. Can anybody tell me how to edit such automatic generated code in Yii?

  • 写回答

1条回答 默认 最新

  • dongwen7813 2014-07-30 11:36
    关注
           $this->author_id = Yii::app()->user->id;
    

    It's bad practice. Because you model depend from your environment. in consequence of dependecy you cant use Unit-test and console command for creating models.

    评论

报告相同问题?