原则自定义数据类型 [英] Doctrine custom data type

查看:122
本文介绍了原则自定义数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Symfony2开发应用程序. Symfony2将Doctrine 2用于DBAL和ORM.据我所知,Doctrine2没有支持BLOB数据类型.但是我想通过自定义数据类型映射实现BLOB支持:

I'm developing application with Symfony2. Symfony2 is using Doctrine 2 for DBAL and ORM. As far as I know Doctrine2 doesn't have suport for BLOB data type. However I want to implement BLOB support through the custom data type mapping:

http://www.doctrine-project.org/docs/dbal /2.0/zh-CN/reference/types.html

但是我一直在努力理解这部分应该去哪里.

However I'm struggling to understand where should this part go.

<?php
Type::addType('money', 'My\Project\Types\MoneyType');
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'money');

有人在经历吗?

我需要BLOB类型的原因是我想从现有的MySQL数据库中导入映射.

The reason I need a BLOB type is that I want to import mapping from existing MySQL database.

推荐答案

另一种解决方案是在配置文件中注册您的自定义类型

Another solution would be to register your Custom Type in the config file

您只需要在配置文件中添加它即可

You just need to add that in your config file:

# app/config/config.yml
doctrine:
    dbal:
        types:
            money:  My\Project\Types\MoneyType

您可以在 Symfony中找到有关如何注册自定义映射类型的更多信息.食谱条目

这篇关于原则自定义数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆