gpt4 book ai didi

php - Symfony 错误 The class XXX was not found in the chain configured namespaces XXX

转载 作者:IT王子 更新时间:2023-10-29 00:11:18 26 4
gpt4 key购买 nike

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

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

$user = new LDAPUser($username);

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

use Client\IntranetBundle\LDAP\LDAPUser;

LDAPUser 实现用户界面

我得到的错误是

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

那是什么意思?据我了解,它与映射有关。

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

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

希望你能帮助我。

编辑#1:

其实我发现不是

$user = new LDAPUser($username);

这是导致错误的原因,但它是在我尝试保留该实体时出现的:

$entityManager->persist($user);

编辑#2:

我对映射出了什么问题感到困惑:

<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="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>

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

最佳答案

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

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

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 下在你的 bundle 中添加命名空间,让 Doctrine 来做这些艰苦的工作。

关于php - Symfony 错误 The class XXX was not found in the chain configured namespaces XXX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22813300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com