https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/working-with-datetime.html
我尝试使用此代码创建 UTC DateTime 类型。但是,代码没有被调用。
令我困惑的是这一节:
use Doctrine\DBAL\Types\Type;
use DoctrineExtensions\DBAL\Types\UTCDateTimeType;
Type::overrideType('datetime', UTCDateTimeType::class);
Type::overrideType('datetimetz', UTCDateTimeType::class);
没有解释应该在哪里调用这段代码。它只说“在引导 ORM 之前”,经过数小时的谷歌搜索后,我仍然没有弄清楚这意味着什么,我现在处于死胡同。
我试图将代码与 UTCDateTimeType 类放在同一个文件中,但这不起作用。
最佳答案
使用 symfony,应在 config/doctrine.yaml
中声明新的学说类型。文件。
doctrine:
dbal:
types:
datetime: DoctrineExtensions\DBAL\Types\UTCDateTimeType
datetimez: DoctrineExtensions\DBAL\Types\UTCDateTimeType
确保类(class)DoctrineExtensions\DBAL\Types\UTCDateTimeType
存在。这是安装空间扩展并声明 geometric types 的完整示例。 .
关于php - 覆盖 DBAL 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61168860/