Symfony2使用Multiuser Bundle和Alice Bundle

时间:2016-03-07 06:23:43

标签: php symfony fosuserbundle

在我的webproject上我一直在使用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)。

我为客户和员工创建了一个新的捆绑包并设置了所有内容。使用应用程序时一切正常。但是生成灯具不再适用了。

在数据文件中,名称空间已更改。

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

我现在已经坚持了几天,有没有人有任何建议?

由于

1 个答案:

答案 0 :(得分:1)

usernameCanonical添加到您的灯具:

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