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.
关于这个问题还有其他一些问题,但没有一个真的有用。我是Symfony的新手,所以我很难理解它。
I am in the file Client\IntranetBundle\LDAP\LDAPAuthenticationProvider.php and this code is causing an error:
我在文件Client \ IntranetBundle \ LDAP \ LDAPAuthenticationProvider.php中,此代码导致错误:
$user = new LDAPUser($username);
I did add it's namespace which is:
我确实添加了它的命名空间,它是:
use Client\IntranetBundle\LDAP\LDAPUser;
LDAPUser implements UserInterface
LDAPUser实现UserInterface
The error I get is
我得到的错误是
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.
那是什么意思?从我读到的内容来看,它与映射有关。
My Doctrine orm in the config.yml is set to:
我在config.yml中的Doctrine orm设置为:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
Hopefully you can help me.
希望你能帮助我。
EDIT #1:
编辑#1:
Actually, I found out that it was not
实际上,我发现事实并非如此
$user = new LDAPUser($username);
That is causing the error, but it is when I am trying to persist this entity:
这导致错误,但是当我试图坚持这个实体时:
$entityManager->persist($user);
EDIT #2:
编辑#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="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?
也许是因为我在两个捆绑之间跳跃?
2 个解决方案
#1
27
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.
默认情况下,auto_mapping功能会查找Entity名称空间下的实体,因此,如果您的实体不存在,则Doctrine对此一无所知。
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:
您需要将实体放在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
As you can see, it's better to put everything under the Entity
namespace in your bundle and let Doctrine do the hard work.
正如您所看到的,最好将所有内容放在捆绑包中的Entity名称空间下,然后让Doctrine进行艰苦的工作。
#2
0
just to help more of you. I've been looking all over the place to fix this error on my project.
只是为了帮助更多的你。我一直在寻找在我的项目上修复此错误的地方。
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”功能中注册。
I hope this one helps you all!
我希望这一个可以帮助你们!
#1
27
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.
默认情况下,auto_mapping功能会查找Entity名称空间下的实体,因此,如果您的实体不存在,则Doctrine对此一无所知。
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:
您需要将实体放在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
As you can see, it's better to put everything under the Entity
namespace in your bundle and let Doctrine do the hard work.
正如您所看到的,最好将所有内容放在捆绑包中的Entity名称空间下,然后让Doctrine进行艰苦的工作。
#2
0
just to help more of you. I've been looking all over the place to fix this error on my project.
只是为了帮助更多的你。我一直在寻找在我的项目上修复此错误的地方。
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”功能中注册。
I hope this one helps you all!
我希望这一个可以帮助你们!