Symfony错误在链配置的命名空间XXX中找不到类XXX

编程入门 行业动态 更新时间:2024-10-26 12:33:00
本文介绍了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.

我在文件Client\IntranetBundle\LDAP\LDAPAuthenticationProvider.php中,此代码导致错误:

I am in the file Client\IntranetBundle\LDAP\LDAPAuthenticationProvider.php and this code is causing an error:

$user = new LDAPUser($username);

我添加了它的命名空间是:

I did add it's namespace which is:

use Client\IntranetBundle\LDAP\LDAPUser;

LDAPUser实现UserInterface

LDAPUser implements UserInterface

错误I get是

The class 'Client\IntranetBundle\LDAP\LDAPUser' was not found in the chain configured namespaces Client\ClientBundle\Entity

这是什么意思?从我读到的,它与映射有关。

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

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

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="doctrine-project/schemas/orm/doctrine-mapping" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="doctrine-project/schemas/orm/doctrine-mapping doctrine-project/schemas/orm/doctrine-mapping.xsd"> <entity name="Client\IntranetBundle\LDAP\LDAPUser" table="users" repository-class="Client\ClientBundle\Repository\UserRepository"> <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: Client\IntranetBundle\LDAP\ 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

本文发布于:2023-11-04 10:24:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中找   错误   空间   Symfony   XXX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!