Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX [英] Symfony error The class XXX was not found in the chain configured namespaces XXX

查看:27
本文介绍了Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经有一些关于这个主题的其他问题,但没有一个是真正有帮助的.我是 Symfony 的新手,所以很难理解它.

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.

我在文件 ClientIntranetBundleLDAPLDAPAuthenticationProvider.php 中,此代码导致错误:

I am in the file ClientIntranetBundleLDAPLDAPAuthenticationProvider.php and this code is causing an error:

$user = new LDAPUser($username);

我确实添加了它的命名空间,即:

I did add it's namespace which is:

use ClientIntranetBundleLDAPLDAPUser;

LDAPUser 实现用户界面

LDAPUser implements UserInterface

我得到的错误是

The class 'ClientIntranetBundleLDAPLDAPUser' was not found in the chain
configured namespaces ClientClientBundleEntity

这是什么意思?据我所知,它与映射有关.

What is that suppose to mean? From what I read it has something to do with the mapping.

我在 config.yml 中的 Doctrine orm 设置为:

My Doctrine orm in the config.yml is set to:

 orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: true

希望你能帮助我.

编辑 #1:

其实我发现不是

$user = new LDAPUser($username);

这是导致错误的原因,但正是在我尝试保留此实体时:

That is causing the error, but it is when I am trying to persist this entity:

$entityManager->persist($user);

编辑 #2:

我对映射的问题感到困惑:

I'm confused with what's wrong with the mapping:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="ClientIntranetBundleLDAPLDAPUser" table="users" repository-class="ClientClientBundleRepositoryUserRepository">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO" />
    </id>
    <field name="username" column="username" type="string" length="100" />
</entity>

也许是因为我在两个包之间跳跃?

Maybe it's because I'm jumping between two bundles?

推荐答案

默认情况下,auto_mapping 功能会在 Entity 命名空间下查找实体,因此鉴于您的实体不在那里,Doctrine 对此一无所知.

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.

您需要将实体置于 Entity 命名空间下或手动配置 Doctrine 以添加自定义实体命名空间.这样你就失去了 auto_mapping 功能,所以你需要手动注册每个包:

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: ClientIntranetBundleLDAP
                    dir: "%kernel.root_dir%/src/Client/IntranetBundle/LDAP/"
                    is_bundle: false

如您所见,最好将所有内容都放在包中的 Entity 命名空间下,让 Doctrine 来完成繁重的工作.

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

这篇关于Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆