Skip to content

Instantly share code, notes, and snippets.

@ixti
Created June 1, 2010 21:14
Show Gist options
  • Save ixti/421508 to your computer and use it in GitHub Desktop.
Save ixti/421508 to your computer and use it in GitHub Desktop.
<?php
class SomeModel extends Doctrine_Record
{
public function setTableDefinition()
{
// ...
$this->hasColumn('some_date', 'date', null, array('notnull' => true, 'notblank' => true));
// ...
}
// ...
public function getSomeDate()
{
$value = $this->_get('some_date');
return ($value) ? new Zend_Date($value, 'YYYY-MM-dd') : $value;
}
public function setSomeDate($value)
{
if ($value instanceof Zend_Date) {
$value = $value->toString('YYYY-MM-dd');
} else if (null !== $value && false === Zend_Date::isDate($value, 'YYYY-MM-dd')) {
throw new App_Exception('Unsupported type or format of some_date');
}
$this->_set('some_date', $value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment