Doctrine Annotations Exception - 奇怪的错误

R. *_*kan 5 php symfony doctrine-orm

当我尝试生成实体或更新架构时;

[Doctrine\Common\Annotations\AnnotationException]
[语义错误]从未导入类Gedmo\Translatable\Entity\Translation中的注释"@index".您是否忘记为此注释添加"使用"语句?

问题是什么?

我试过了;

  • 清除缓存,
  • 清除学说缓存,
  • 文件模式,
  • 乔恩,
  • 作曲家更新

更多信息:

我现在不使用gedmo翻译.它已安装但未使用!

我没有使用翻译注释.

将symfony2.4更新为2.6后发生这种情况.

Jas*_*wer 7

这是一个错误

不幸的是,类doc-block Gedmo\Translatable\Entity\Translation包含注释@index(而不是@Index使用大写"I").这可能会导致区分大小写的文件系统出现问题.

这已在commit 1926773中修复:删除了未使用的use语句并添加了一个缺失的语句,但尚未标记/发布.

因为您升级了Symfony,所以您可能还升级了Doctrine.我不确定发生了哪种版本的Doctrine,但过去遗漏的注释只是被忽略了.如今抛出异常.这可能是升级后遇到此问题的原因.

禁用缺少注释异常

一种解决方案是忽略@index(小写"i")注释:

AnnotationReader::addGlobalIgnoredName('index');
Run Code Online (Sandbox Code Playgroud)

文件:2.2.3.忽略遗漏的异常

或者完全禁用导入验证机制:

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setEnabledPhpImports(false);
Run Code Online (Sandbox Code Playgroud)

文件:2.2.4.PHP进口

请注意,将在Doctrine的未来版本中删除最后一个功能.

禁用可翻译映射

即使您没有使用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
Run Code Online (Sandbox Code Playgroud)

您应该包含您实际使用的扩展名的映射.

升级gedmo/doctrine-extensions

gedmo/doctrine-extensions您的要求更改composer.json为至少1926773.您还可以要求维护者发布包含错误修复的新版本.