关于
这个主题已经有一些其他问题了,但没有一个是真正有帮助的。我是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 中的教义或设置为:
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
命名空间下,让 Doctrine 完成艰苦的工作。
我的错误是我忘记在AppKernel
文件中的"供应商"中添加远距离捆绑包/捆绑包。
它们未在registerBundles()
方法中注册。
您的捆绑包应该与您用于config/packages/doctrine.yaml
(Symfony4)配置文件中的服务/命令/API的正确实体管理器进行映射。
例如,在以下原则配置中,BundleName
与default
实体管理器映射,因此使用实体管理器default
策略连接的代码可以访问和使用BundleName
的实体和存储库。
orm:
entity_managers:
default:
mappings:
BundleName: