Php Symfony2注释“@Gedmo\Mapping\Annotation\Timestable";不存在,或无法自动加载

Php Symfony2注释“@Gedmo\Mapping\Annotation\Timestable";不存在,或无法自动加载,php,mongodb,symfony,doctrine-orm,Php,Mongodb,Symfony,Doctrine Orm,看起来注释或名称空间的路径是错误的,但我不明白为什么php-bin/console原则:mongodb:mapping:infooutputs [FAIL] AppBundle\Document\Test\Test [Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Timestampable" in property AppBundle\Document\Test\Test::$createdAt does not exis

看起来注释或名称空间的路径是错误的,但我不明白为什么
php-bin/console原则:mongodb:mapping:info
outputs

[FAIL] AppBundle\Document\Test\Test
[Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Timestampable" in property AppBundle\Document\Test\Test::$createdAt does not exist, or could not be auto-loaded.
实体文件:

<?php

namespace AppBundle\Document\Test;

use AppBundle\Document\Question\Question;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @MongoDB\Document(repositoryClass="AppBundle\Document\Test\TestRepository")
 * @MongoDB\HasLifecycleCallbacks()
 */
class Test
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;


    /**
     * @MongoDB\Field(type="string")
     */
    protected $lastName;


    /**
     * @Gedmo\Timestampable(on="create")
     * @MongoDB\Timestamp()
     */
    protected $createdAt;
是的,我有
AnnotationDriver::registernotationclasses()在autoload.php中。我已经看过了
vendor/composer/autoload_namespaces.php
,看起来也不错:

<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
[...]
    'Gedmo\\' => array($vendorDir . '/gedmo/doctrine-extensions/lib'),
    'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
    'Doctrine\\ODM\\MongoDB' => array($vendorDir . '/doctrine/mongodb-odm/lib'),
    'Doctrine\\MongoDB' => array($vendorDir . '/doctrine/mongodb/lib'),
    'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'),
    'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
    'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
    'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'),
    'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib'),
    'Behat\\Transliterator' => array($vendorDir . '/behat/transliterator/src'),
);

找到有效的解决方案。必须手动将注释文件添加到autoload.php中的注册表:

AnnotationRegistry::registerFile(__DIR__ . '/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Mapping/Annotation/Timestampable.php');
根据:您需要在您的
app/config.yml
中激活可翻译文件:

stof_doctrine_extensions:
    mongodb:
        default:
            translatable: true
并将翻译实体映射添加到条令:

doctrine:
    orm:
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Document
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Document"
                alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
                is_bundle: false
            gedmo_translator:
                type: annotation
                prefix: Gedmo\Translator\Document
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Document"
                alias: GedmoTranslator # (optional) it will default to the name set for the mapping
                is_bundle: false

你在config.yml中启用了吗?我想是的<代码>doctrine\u mongodb:连接:默认值:服务器:“mongodb://%mongodb\u主机%:%mongodb\u端口%”选项:{}文档管理器:默认值:自动映射:true
我询问了
stof\u doctrine\u扩展
部分(请阅读NDM的答案)
stof_原则扩展:mongodb:default:timestable:true
Author使用ODM,而不是ORM。但是选项应该是相似的。如果您是正确的,我已更改为配置以反映MongodBt感谢您的回复,但不需要更改
app/config.yml
。现在,即使autoload.php中没有“AnnotationRegistry::registerFile”,它也可以工作。可能是缓存/日志问题。有趣的是,只有在使用
php-bin/console-cache:clear
清除缓存后第一次运行时,才需要进行上述更改。在第一次运行时,我还必须添加
AnnotationRegistry::registerFile(_DIR__.'/../vendor/sensio/framework extra bundle/Configuration/Route.php')。否则,路由将不起作用。
doctrine:
    orm:
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Document
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Document"
                alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
                is_bundle: false
            gedmo_translator:
                type: annotation
                prefix: Gedmo\Translator\Document
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Document"
                alias: GedmoTranslator # (optional) it will default to the name set for the mapping
                is_bundle: false