Symfony2-类';X';在链配置的命名空间中找不到


Symfony2 - The class 'X' was not found in the chain configured namespaces

我一直在寻找解决问题的方法。但我找不到任何解决方案。

当我试图打开主页时,我总是收到这样的错误消息:

未捕获异常"Doctrine''Common''Persistence''MMappingException",消息为"在链配置的命名空间中找不到类"Test''Bundle''UserBundle''Entity''User"…

奇怪的是,只有当我有以下URL时,我才会得到它:

http://localhost/

但当我在这个URL上运行它时,我没有得到任何错误,我的页面显示正确:

http://localhost/app_dev.php

我的配置如下(config.yml(:

# Doctrine Configuration
dbal:
  default_connection: default
  connections:
    default:
      driver:   "%database_driver%"
      host:     "%database_host%"
      port:     "%database_port%"
      dbname:   "%database_name%"
      user:     "%database_user%"
      password: "%database_password%"
      charset:  UTF8
    test:
      driver:   "%database_driver2%"
      host:     "%database_host2%"
      port:     "%database_port2%"
      dbname:   "%database_name2%"
      user:     "%database_user2%"
      password: "%database_password2%"
      charset:  UTF8
orm:
  default_entity_manager: default
  entity_managers:
    default:
      connection: default
      mappings:
        TestUserBundle:
          type: annotation

我在我的定制服务中称之为条令:

public function __construct(EntityManager $em)
{
    $repositiory = $em->getRepository('Test'Bundle'UserBundle'Entity'User');
    $this->user = $repositiory->find($_SERVER['AUTH_USER']);
}

我的Symfony应用程序正在IIS Web服务器上运行。

你们知道我哪里搞错了吗?

映射名称为TestUserBundle,但路径为Test'Bundle'User'Bundle,不应该将其命名为TestBundleUserBundle吗?此外,通常在开发模式下,mappingsauto_generate_proxy_classes被设置为true,这可能解释了为什么它在那里工作而不是在产品中。

您可能需要查看文档(Symfony 2.7(,其中显示了根据您的情况应该如何配置映射。

绑定中的自定义映射实体

doctrine:
    # ...
    orm:
        # ...
        auto_mapping: true
        mappings:
            # ...
            AppBundle:
                type: xml
                dir: SomeResources/config/doctrine

映射束外的实体

doctrine:
    # ...
    orm:
        # ...
        mappings:
            # ...
            SomeEntityNamespace:
                type: annotation
                dir: "%kernel.root_dir%/../src/Entity"
                is_bundle: false
                prefix: App'Entity
                alias: App

最后,但同样重要的是,在对config.ymlapp/config/目录中的文件进行更改后,请始终清除缓存目录。

如评论中所述:您需要暂时停止任何可能使用prod目录的PHP进程(即,如果您运行了console server:run(,然后重试。如果没有,请尝试这个

事实证明,我的错误是忘记在AppKernel文件中的"vendor"中添加遥远的bundle/bundle。

它们没有在"registerBundles"函数中注册。