如何使用Symfony 2在Doctrine 2中添加BLOB类型 [英] How add BLOB type in Doctrine 2 using Symfony 2

查看:106
本文介绍了如何使用Symfony 2在Doctrine 2中添加BLOB类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Symfony 2中,我生成一个用于将任何类型的文档存储到数据库中的Bundle,但是我需要BLOB列类型。

In Symfony 2 I generate a Bundle for storing any type of document into database, but I need the BLOB column type.

Tnx to 这个问题我添加了类BlobType到Doctrine DBAL,但是为了使用我不得不更改的新列类型

Tnx to this question I add the class BlobType into Doctrine DBAL, but for use the new column type I had to change

Doctrine\DBAL\Types\Type

[...]

const BLOB = 'blob';

[...]

private static $_typesMap = array(
    [...],
    self::BLOB => 'Doctrine\DBAL\Types\BlobType',
);

Doctrine\DBAL\Platforms\MySqlPlatform (也许是更好的,如果我改变了Doctrine\DBAL\Platforms\AbstractPlatform)

Doctrine\DBAL\Platforms\MySqlPlatform (maybe it was better if I had changed Doctrine\DBAL\Platforms\AbstractPlatform)

[...]
protected function initializeDoctrineTypeMappings()
{
    $this->doctrineTypeMapping = array(
        [...],
        'blob'          => 'blob',
    );
}

[...]

/**
 * Obtain DBMS specific SQL to be used to create time fields in statements
 * like CREATE TABLE.
 *
 * @param array $fieldDeclaration
 * @return string
 */
public function getBlobTypeDeclarationSQL(array $fieldDeclaration) 
{
    return 'BLOB';
}   

现在我没有mouch时间, ',但是将来我想恢复Doctrine类,并且可以将新的列类型分配给Symfony 2引导。
我想我应该编辑我的app / bootstrap.php.cache,但是我不知道如何进行干预。

Now I don't have mouch time for a 'pretty solution', but in future I would like to restore the Doctrine classes and be able to assign the new column type into Symfony 2 bootstrap. I think I should edit my app/bootstrap.php.cache but I don't have idea how to intervene.

推荐答案

这对我有用:


  1. 创建你的blobtype(见 https://gist.github.com/525030/38a0dd6a70e58f39e964ec53c746457dd37a5f58

添加这到你的Bundle初始化(/src/YOURDOMAIN/YOURBUNDLE/YOURDOMAINYOUBUNDLE.php)

add this to your Bundle initialization (/src/YOURDOMAIN/YOURBUNDLE/YOURDOMAINYOUBUNDLE.php)

class YourBundle extends Bundle
{
    public function boot()
    {
        $em = $this->container->get('doctrine.orm.entity_manager');
        Type::addType('blob', 'YOURDOMAIN\YOURBUNDLE\YOURTYPEDIRECTORY\BlobType');
        $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('blob','blob');        
    }
}


这篇关于如何使用Symfony 2在Doctrine 2中添加BLOB类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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