php - 原则 2 - 如何使用时间列类型

标签 php symfony doctrine-orm

我的时间列类型有问题: 我有我的实体“匹配”的这一部分:

/**
 * @ORM\Column(type="date")
 */
private $creationDate;
/**
 * @ORM\Column(type="time",nullable=true)
 */
private $creationTime;

每次我尝试保留实体时,我都会收到错误消息:

错误:调用 TimeType.php 中字符串的成员函数 format()

这是我填充 CreationTime 的部分:

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

$Match->setCreationTime($time); 

我试图检查 TimeType.php 文件,我发现这个函数是问题的根源:

public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
    return ($value !== null)
        ? $value->format($platform->getTimeFormatString()) : null;
}

为了更加确定,我检查了 AbstractPlatform 类并发现成员方法 getTimeFormatString 总是返回此字符串:'H:i:s'。

所以任何机构都可以提供帮助?

最佳答案

尝试使用这个:

$Match->setCreationTime(new \Datetime());

关于php - 原则 2 - 如何使用时间列类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44474462/

相关文章:

php - 奏鸣曲管理包 : possible to add a child admin object that can have different parents?

php - 教义2获取代理类的真实类名

php - 当 mysql 中存在 unicode 字符时,无法将条目存储为字符串

php - Doctrine 2 : Is there a way to inherit mapping from a trait using yaml or xml?

php - PHP shell_exec 中的 FFMPEG 命令对于 300Mo mp4 来说太慢了

php - 当进程意外死亡时,flock'ed 文件会被解锁吗?

linux - Linux 中因版本变更而出现的符号

php - 调用两次时 mysql_connect 的行为

php - Symfony 控制台 ContainerAwareCommand $this->getContainer() 产生 fatal error

html - 如何将 CSS ID 属性设置为 Symfony2 表单输入