views:

414

answers:

1

I have Doctrine model with a date field "date_of_birth" (symfony form date) which is filled in by the user all works 100% it saves to the db as expected, however in the model save() method I need to retrieve the value of this field before save occurs. My problem is that When trying to get the date value it returns empty string if its a new record and the old value if it is an existing record

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);
 }

How Can I retrieve the value of this field beore data is saved

+1  A: 

You can try overriding preSave doctrine pseudo-event :

public function preSave($event) {
   $dob = $this->getDateOfBirth();

   //do whatever you need

   parent::preSave($event);
}
Benoit