在我的网络项目中,我一直在使用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 多用户捆绑包 (https://github.com/rollerworks/RollerworksMultiUserBundle)。
我为客户和员工创建了一个新的捆绑包,并设置了所有内容。使用该应用程序时,一切正常。但是生成夹具不再起作用。
在数据文件中,只是命名空间发生了变化。
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 命令(或运行也执行生成 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
添加到您的灯具中:
Users'StaffBundle'Entity'Staff:
staff_1:
usernameCanonical: <identity($username)>
其他员工条目也是如此。您的User
可能有根据用户名值自动填充它的逻辑。
确保您的Users'StaffBundle'Entity'Staff
实现了FOS'UserBundle'Model'UserInterface
并调用了FOS'UserBundle'Doctrine'UserListener
(它将在保存用户之前调用updateCanonicalFields
和updatePassword
)。
在此处阅读更多内容: http://symfony.com/doc/current/bundles/FOSUserBundle/user_manager.html#updating-a-user-object