简体   繁体   English

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

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

I've been searching forever to solve my problem. 我一直在寻找解决我的问题。 But I can't find any solution. 但我找不到任何解决方案。

I always get this error message when I try to open the homepage: 我尝试打开主页时总是收到此错误消息:

Uncaught exception 'Doctrine\\Common\\Persistence\\Mapping\\MappingException' with message 'The class 'Test\\Bundle\\UserBundle\\Entity\\User' was not found in the chain configured namespaces ' in... 未捕获的异常'Doctrine \\ Common \\ Persistence \\ Mapping \\ MappingException',消息'在'链配置的命名空间'中找不到类'Test \\ Bundle \\ UserBundle \\ Entity \\ User'...

The weird thing is that I only get it when I have following URL: 奇怪的是,当我有以下网址时,我才会得到它:

http://localhost/ HTTP://本地主机/

But when I run it on this URL I don't get any error and my page is being displayed correctly: 但是当我在这个URL上运行它时,我没有收到任何错误,我的页面正确显示:

http://localhost/app_dev.php HTTP://localhost/app_dev.php

My Configuration looks like this (config.yml): 我的配置看起来像这样(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

And I call Doctrine in my custom service like this: 我在我的自定义服务中调用Doctrine,如下所示:

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

My Symfony Application is running on an IIS Webserver. 我的Symfony应用程序正在IIS Web服务器上运行。

Do you guys know where I made a mistake? 你们知道我弄错了吗?

Mapping name is TestUserBundle but the path is Test\\Bundle\\User\\Bundle , shouldn't it be named TestBundleUserBundle instead? 映射名称是TestUserBundle但路径是Test\\Bundle\\User\\Bundle ,不应该将其命名为TestBundleUserBundle吗? Also, usually the mappings and auto_generate_proxy_classes are set to true in dev mode which might explain why it's working there and not in prod. 此外,通常在开发模式下将mappingsauto_generate_proxy_classes设置为true ,这可能解释了为什么它在那里工作而不是prod。

You might want to checkout the documentation (Symfony 2.7) which shows how exactly you should be configuring the mappings depending on your case. 您可能需要查看文档 (Symfony 2.7),该文档根据您的具体情况显示您应该如何配置映射。

Custom Mapping Entities in a Bundle 捆绑包中的自定义映射实体

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

Mapping Entities Outside of a Bundle 映射捆绑包外的实体

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

Last, but not least, always clear your cache directory after applying changes to the config.yml or files in the app/config/ directory. 最后,但并非最不重要的是,在对config.ymlapp/config/目录中的文件应用更改后,始终清除缓存目录。

As mentioned in the comments: You need to temporarily stop any PHP processes that might be using the prod directory (ie if you've ran console server:run) and try again. 如评论中所述:您需要暂时停止可能正在使用prod目录的任何PHP进程(即,如果您已运行控制台服务器:运行)并再次尝试。 If that doesn't do it, try this 如果不这样做,试试这个

It turns out that my mistake was that I forgot to add distant bundles/bundles in "vendor" inside my AppKernel file. 事实证明,我的错误是我忘记在我的AppKernel文件中的“vendor”中添加远程bundle / bundles。

They weren't registered in the "registerBundles" function. 它们未在“registerBundles”功能中注册。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在链配置的名称空间异常中找不到Symfony2多个文件上载 - Symfony2 Multiple File Upload was not found in the chain configured namespaces exception Symfony + Doctrine ODM“在链配置的名称空间CoreBundle / Document中找不到该类” - Symfony + Doctrine ODM “The class was not found in the chain configured namespaces CoreBundle/Document” Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX - Symfony error The class XXX was not found in the chain configured namespaces XXX 服务中的“未在已配置链的命名空间中找到X” - 'X was not found in the chain configured namespaces' in service 在提交表单期间,在链配置的名称空间中找不到类'Symfony \\ Component \\ Form \\ Form' - The class 'Symfony\Component\Form\Form' was not found in the chain configured namespaces during Form Submission MappingException - 在链配置的命名空间 xxx 中找不到 class 'generalBundle\Entity\xxx' - 升级到 symfony flex - MappingException - The class 'generalBundle\Entity\xxx' was not found in the chain configured namespaces xxx - Upgrade to symfony flex 主义试图两次加载元数据。 在链配置的名称空间中找不到类“ x” - Doctrine trying to load metadata twice. The class 'x' was not found in the chain configured namespaces 在Symfony2中链中找不到Doctrine可翻译类 - Doctrine Translatable class not found in chain in Symfony2 在链配置的命名空间中找不到类“App\\Entity\\Users” - The class 'App\Entity\Users' was not found in the chain configured namespaces 在链配置的名称空间中找不到类'DoctrineModule \\ Stdlib \\ Hydrator \\ DoctrineObject' - The class 'DoctrineModule\Stdlib\Hydrator\DoctrineObject' was not found in the chain configured namespaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM