Doctrine2:类型 x 已经存在 [英] Doctrine2: Type x already exists

查看:36
本文介绍了Doctrine2:类型 x 已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Doctrine API 时遇到问题.

I have a problem with the Doctrine API.

我想添加一个新的教义类型.我按照此文档创建了类,并在自定义驱动程序中添加了类型.

I want to add a new Doctrine Type. I followed this documentation to create the class, and I have added the type in my custom driver.

Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
$this->registerDoctrineTypeMapping("CustomType", "custom");

当我执行 php app/console cache:clear 时我的问题追加.

My problem append when I execute php app/console cache:clear.

[Doctrine\DBAL\DBALException]
Type custom already exists.

经过几次搜索,我发现在 Doctrine\DBAL\Types\Type::addType(...) 中,如果类型已知,则会抛出异常...我不明白为什么会抛出此错误.

After few searches, I have found in Doctrine\DBAL\Types\Type::addType(…) throw an exception if the type is knew… I don't understand why this error is throwing.

推荐答案

我发现了我的问题!

我不知道为什么,但我的自定义类型一次又一次地加载.

I don't know why, but my custom type is loading again and again.

为了解决这个问题,添加这个代码就像检查一样.

To resolve this problem, adding this code like checking.

if (!Type::hasType("custom")) {
    Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
    $this->registerDoctrineTypeMapping("CustomType", "custom");
}

有效!

这篇关于Doctrine2:类型 x 已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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