tags:

views:

69

answers:

1

i have a datatime field

/**
 * Date time posted
 * @Column(type="datetime")
 */
private $dtPosted;

set to a default value by use of a LifeCycleCallback

/**
 * @PrePersist
 */
function onPrePersist() {
    // set default date
    $this->dtPosted = date('Y-m-d H:m:s');

i am getting

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

A: 

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.

you are right. i shld use `date_create(date(...))` or `DateTime::__construct()`
jiewmeng