gpt4 book ai didi

php - Symfony2 使用 Multiuser Bundle 和 Alice Bundle

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:07 27 4
gpt4 key购买 nike

在我的网络项目中,我一直在使用 Hautelook Alice Bundle ( https://github.com/hautelook/AliceBundle ) 来创建用于开发和测试的装置。对于用户管理,我使用的是 FOS UserBundle。我的数据文件看起来有点像这样,它过去工作得很好:

AppBundle\Entity\StaffDetail:
staffdetail_{1..5}:
prefix: <title()>
first_name: <firstName()>
last_name: <lastName()>

AppBundle\Entity\Staff:
staff_1:
username: admin@example.com
plainpassword: password
email: admin@example.com
mandant: @mandant_1
enabled: true
role: administrator
staffdetail: @staffdetail_1
staff_{2..5}:
username (unique): <safeEmail()>
plainpassword: password
email: <identity($username)>
mandant: @mandant_1
enabled: true
role: administrator
staffdetail: @staffdetail_<current()>

现在我正在尝试为不同的用户组(员工和客户)使用不同的登录机制,所以我想使用 Rollerworks Multi User Bundle ( https://github.com/rollerworks/RollerworksMultiUserBundle )。

我为客户和员工创建了一个新的 bundle 并设置了所有内容。使用该应用程序时,一切正常。但是生成固定装置不再起作用。

在数据文件中,只是命名空间发生了变化。

Users\StaffBundle\Entity\StaffDetail:
staffdetail_{1..5}:
prefix: <title()>
first_name: <firstName()>
last_name: <lastName()>

Users\StaffBundle\Entity\Staff:
staff_1:
username: admin@example.com
plainpassword: password
email: admin@example.com
mandant: @mandant_1
enabled: true
role: administrator
staffdetail: @staffdetail_1
staff_{2..5}:
username (unique): <safeEmail()>
plainpassword: password
email: <identity($username)>
mandant: @mandant_1
enabled: true
role: administrator
staffdetail: @staffdetail_<current()>

当我运行 fixtures 命令(或运行同时执行 generate fixtures 命令的测试)时,它似乎只是试图将值插入数据库,而不是首先为实体运行 FOS UserBundle 构造函数,作为密码, username_canonical 等未设置。

[Doctrine\DBAL\DBALException]
An exception occurred while executing 'INSERT INTO staff (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_tok
en, password_requested_at, roles, credentials_expired, credentials_expire_at, role, staffdetail_id, mandant_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["ad
min@example.com", null, "admin@example.com", null, 1, "kbttb26978gkkcosk404wccgc4os8wo", null, null, 0, 0, null, null, null, "a:0:{}", 0, null, "administrator", 22, 13]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'username_canonical' cannot be null

我已经坚持了几天了,有人有什么建议吗?

谢谢

最佳答案

usernameCanonical 添加到您的 fixture:

Users\StaffBundle\Entity\Staff:
staff_1:
usernameCanonical: <identity($username)>

其他员工条目也是如此。您的 User 可能具有根据用户名值自动填充的逻辑。

确保你的 Users\StaffBundle\Entity\Staff 实现了 FOS\UserBundle\Model\UserInterfaceFOS\UserBundle\Doctrine\UserListener 被调用(它会在保存用户之前调用 updateCanonicalFieldsupdatePassword)。

在这里阅读更多:http://symfony.com/doc/current/bundles/FOSUserBundle/user_manager.html#updating-a-user-object

关于php - Symfony2 使用 Multiuser Bundle 和 Alice Bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35837433/

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