存储覆盖/保存前的主义日期

wik*_*nne 6 doctrine symfony1 save

我有一个带有日期字段"date_of_birth"(symfony表单日期)的Doctrine模型,由用户填写所有工作100%它按预期保存到db,但是在模型save()方法中我需要检索值保存之前发生此字段.我的问题是,当试图获取日期值时,如果它是新记录则返回空字符串,如果是现有记录则返回旧值

public function save(Doctrine_Connection $conn = null)
{
      $dob = $this->getDateOfBirth(); // returns empty str if new and old value if existing
      $dob = $this->date_of_birth; //also returns empty str

      return parent::save($conn);
 }
Run Code Online (Sandbox Code Playgroud)

如何检索此字段的值beore数据已保存

Ben*_*oit 7

在Doctrine 1.2中,您可以覆盖preSave伪事件:

// In your model class
public function preSave($event) {
   $dob = $this->getDateOfBirth();

   //do whatever you need

   parent::preSave($event);
}
Run Code Online (Sandbox Code Playgroud)

在Doctrine 2.1中,函数名称已更改.