bin*_*ram 3 php types symfony doctrine-orm
我想在我的Symfony 3.2应用程序中使用Carbon对象而不是SPL\DateTime对象.我在这里找到了一组DoctrineExtension类.
编辑我的config.yml文件:
doctrine:
dbal:
...
types:
carbondatetime: DoctrineExtensions\Types\CarbonDateTimeType
carbondate: DoctrineExtensions\Types\CarbonDateType
carbontime: DoctrineExtensions\Types\CarbonTimeType
mapping_types:
datetime: carbondatetime
date: carbondate
enum: string
time: carbontime
Run Code Online (Sandbox Code Playgroud)
我成功检查了类型是否加载:
Doctrine\DBAL\Types\Type::getTypesMap()
Run Code Online (Sandbox Code Playgroud)
并且映射也正常工作(返回carbondatetime):
$this->getDoctrine()->getManager()
->getConnection()->getDatabasePlatform()
->getDoctrineTypeMapping('datetime');
Run Code Online (Sandbox Code Playgroud)
我在Doctrine存储库上执行查询,仍然获取DateTime对象.它有两种情况:
@ORM\Column(type="carbondatetime")\Doctrine\DBAL\Types\Type::overrideType('datetime', 'DoctrineExtensions\Types\CarbonDateTimeType');是否有最佳实践来覆盖 Doctrine DBAL类型?优选地,在YAML配置中.
谢谢
哇....像往常一样,一旦你提出问题,你就会找到解决方案:
doctrine:
dbal:
...
types:
datetime: DoctrineExtensions\Types\CarbonDateTimeType
date: DoctrineExtensions\Types\CarbonDateType
time: DoctrineExtensions\Types\CarbonTimeType
mapping_types:
enum: string
Run Code Online (Sandbox Code Playgroud)