Doctrine 2: Call to a member function format() on a non-object … in DateTimeType.php

前端 未结 4 1781
北海茫月
北海茫月 2020-12-09 15:37

I have a DateTime field:

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

which is set to a defau

4条回答
  •  抹茶落季
    2020-12-09 16:13

    Try and use your setCreated with annotations for @ORM\PrePersist and setUpdated with annotations for @ORM\PrePersist and @ORM\PreUpdate methods as opposed to prePersist and preUpdate methods...

    /**
     * @ORM\PrePersist
     */
    public function setCreated()
    {
        $this->created = new \DateTime();
    }
    
    /**
     * @ORM\PrePersist
     * @ORM\PreUpdate
     */
    public function setUpdated()
    {
        $this->updated = new \DateTime();
    }
    

提交回复
热议问题