且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

symfony 3.4 类型错误:参数 1 传递给 ... 必须是 DateTime 的实例,给定 null,

更新时间:2021-12-13 22:41:16

更好的解决方案是允许设置 null 并让验证报告错误.

Better solution is to allow set the null and let the validation reports the error.

/**
 * @var \DateTime
 * @ORM\Column(name="task_date_start", type="datetime", nullable=false)
 * @Assert\NotBlank()
 */
 private $taskDateStart;

 function setTaskDateStart(?\DateTime $taskDateStart) {
     $this->taskDateStart = $taskDateStart;
 }