Symfony error The class XXX was not found in the chain configured namespaces XXX

后端 未结 3 625
栀梦
栀梦 2020-11-29 09:59

There are some other questions on this subject already, but none of them were really helpful. I am new to Symfony, so it\'s pretty hard to get my head around it.

I

相关标签:
3条回答
  • 2020-11-29 10:31

    My mistake was that I forgot to add distant bundles/bundles in "vendor" inside my AppKernel file.

    They weren't registered in the registerBundles() method.

    0 讨论(0)
  • 2020-11-29 10:34

    By default, the auto_mapping feature looks for entities under the Entity namespace, so given that your entity is not there, Doctrine does not know anything about it.

    You need to put your entity under the Entity namespace or configure Doctrine by hand to add your custom entity namespace. This way you lose the auto_mapping feature, so you would need to register every bundle manually:

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        entity_managers:
            default:
                mappings:
                    MyBundle:
                        type: annotation
                    custom_mapping:
                        type: annotation
                        prefix: Client\IntranetBundle\LDAP\
                        dir: "%kernel.root_dir%/src/Client/IntranetBundle/LDAP/"
                        is_bundle: false
    

    As you can see, it's better to put everything under the Entity namespace in your bundle and let Doctrine do the hard work.

    0 讨论(0)
  • 2020-11-29 10:49

    Your bundle should be mapped with correct entity managers you are using for service / command / api in config/packages/doctrine.yaml (Symfony4) config file.

    For example In following doctrine config, BundleName is mapped with default entity managers so code using default entity managers doctrine connection can access and use BundleName's entities and repositories.

    orm:
        entity_managers:
            default:
                mappings:
                  BundleName:
    
    0 讨论(0)
提交回复
热议问题