I've come across inconsistent behaviour between docs and actual implementation. For assigning date here (https://phalcon-php-framework-documentation.readthedocs.org/en/latest/reference/models.html#implementing-events-in-the-model-s-class) is advised to use either event manager
public function beforeCreate()
{
//Set the creation date
$this->created_at = date('Y-m-d H:i:s');
}
or Behaviors
public function initialize()
{
$this->addBehavior(new Timestampable(
array(
'beforeCreate' => array(
'field' => 'created_at',
'format' => 'Y-m-d'
)
)
));
}
But in practice it doesn't work because of the failed validation! You have to use either
public function beforeValidationOnCreate()
{
$this->created_at = date('Y-m-d H:i:s');
}
or
protected function _preSave()
{
$this->created_at = date('Y-m-d H:i:s');
}