I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this:
class ScheduleItem { private Date start; //A PEAR Date object. private Date end; public function getStart() { return $this->start; } public function setStart($val) { $this->start = $val; } public function getEnd() { return $this->end; } public function setEnd($val) { $this->end= $val; } }
I have a ScheduleItemDAO
class with methods like save()
, getByID()
, etc. When loading from and saving to the database, the DAO class converts the Date
objects to and from strings so they can be stored in a timestamp field.
In my attempt to move to Doctrine, I created a new class like this:
class ScheduleItem extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn( start , timestamp ); $this->hasColumn( end , timestamp ); } }
I had hoped I would be able to use Date
objects for the start and end times, and have them converted to strings when they are saved to the database. How can I accomplish this?