Doctrine 2.1 - datetime column default value

前端 未结 7 1220
小蘑菇
小蘑菇 2020-12-30 18:51

Could someone tell me how to add default value on datetime column? I can\'t do this like this:

protected $registration_date = date(\"Y-m-d H:i:s\", time());
         


        
相关标签:
7条回答
  • 2020-12-30 19:32

    You can also use lifecycle callbacks if you want to be very precise:

    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\HasLifecycleCallbacks
     * ...
     */
    class MyEntity
    {
        /**
         * @ORM\PrePersist
         */
        public function onPrePersistSetRegistrationDate()
        {
            $this->registration_date = new \DateTime();
        }
    }
    
    0 讨论(0)
提交回复
热议问题