当我尝试生成实体或更新架构时;
[学说\通用\注释\注释异常]
[语义错误] 从未导入类 Gedmo\Translatable\Entity\Translation 中的注释“@index”。您是否忘记为该注释添加“使用”语句?
问题是什么?
我试过了;
- 清除缓存,
- 清除学说缓存,
- 修改,
- 乔恩,
- Composer 更新
更多信息:
我现在不使用 gedmo 翻译。它已安装但未使用!
我没有使用任何翻译注释。
这是在将 symfony2.4 更新到 2.6 之后发生的。
最佳答案
这是一个错误
不幸的是,Gedmo\Translatable\Entity\Translation
的类文档 block 包含注释 @index
(而不是 @Index
,大写“I”)。这可能会导致区分大小写的文件系统出现问题。
这已在提交 1926773: Removed unused use statements and added a missing one 中修复,但尚未标记/发布。
因为你升级了 Symfony,你可能也升级了 Doctrine。我不确定这发生在哪个版本的 Doctrine 中,但在过去,缺少的注释被简单地忽略了。现在抛出异常。这可能就是您在升级后遇到此问题的原因。
禁用缺失注释异常
一种解决方案是忽略 @index
(小写的“i”)注释:
AnnotationReader::addGlobalIgnoredName('index');
文档:2.2.3. Ignoring missing exceptions
或者完全禁用导入验证机制:
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setEnabledPhpImports(false);
请注意,最后一个功能将在 Doctrine 的 future 版本中删除。
禁用可翻译映射
即使您没有使用 Translatable 扩展,您也可能启用了它的映射。 否则不会加载该类,也不会发生错误。
在你的 app/config/config.yml
中搜索这样的东西:
doctrine:
orm:
entity_managers:
default:
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator
is_bundle: false
您应该仅包括您实际使用的扩展的映射。
升级 gedmo/doctrine-extensions
将 composer.json
中的 gedmo/doctrine-extensions
的要求更改为至少 1926773。您也可以要求维护者发布一个新版本,其中包括错误修复。
关于php - Doctrine Annotations Exception - 奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25221619/