symfony 如何设置'DateTimeInterface'默认值

e0bqpujr  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(110)

我有这个DateTimeInterface,我想在Symfony6中设置默认值

#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updatedAt = new \DateTimeMutable('now');

但是这里写的是New expressions are not supported in this context
如何设置默认值?

tktrz96b

tktrz96b1#

可以在构造函数中使用默认值

public function __construct(\DateTimeInterface date = new DateTime("now")) {
  $this->updatedAt = date;
}

祝你今天愉快!

相关问题