I have a DateTime
field:
/**
* Date time posted
* @Column(type="datetime")
*/
private $dtPosted;
which is set to a default value by using a LifeCycleCallback
/**
* @PrePersist
*/
function onPrePersist() {
// set default date
$this->dtPosted = date('Y-m-d H:m:s');
I am getting the following error:
Fatal error: Call to a member function format() on a non-object in D:\ResourceLibrary\Frameworks\Doctrine\lib\Doctrine\DBAL\Types\DateTimeType.php on line 46
The date()
function returns a string. The datetime
type works with DateTime
objects. So either change the mapping type to string
or use DateTime
objects.