【问题标题】:Creating a new user with FOSUserBundle fails使用 FOSUserBundle 创建新用户失败
【发布时间】:2012-12-25 23:27:47
【问题描述】:

我正在尝试从命令行创建一个新用户并收到此错误:

Warning: array_search() expects parameter 2 to be array, null given
in /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Model/User.php line 368  

当尝试通过网络界面注册来创建用户时,我得到了这个:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'salt' cannot be null

使用现有用户登录即可。还更新配置文件和更改密码。仅仅创建新用户是行不通的。

我在一个非常简单的设置中使用 v 1.3.1,但还没有找到任何解决方案。

有什么想法吗?

【问题讨论】:

    标签: symfony fosuserbundle


    【解决方案1】:

    已修复!

    我的用户实体中有一个自定义构造方法。在那里我忘了用parent::__construct();调用父的构造函数

    【讨论】:

      【解决方案2】:

      也许它可以帮助某人。使用 bcrypt 编码器时会出现此错误。

      SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'salt' cannot be null
      

      要解决这个问题,只需在您的用户类中添加盐属性的映射覆盖(使其可以为空)

      use FOS\UserBundle\Model\User as BaseUser;
      use Doctrine\ORM\Mapping as ORM;
      
      /**
       * @ORM\Entity
       * @ORM\AttributeOverrides({
       *  @ORM\AttributeOverride(
       *      name="salt",
       *      column=@ORM\Column(name="salt", type="string", nullable=true)
       *      )
       *  })
       */
      class User extends BaseUser {
           ...
      }
      

      或者:不要忘记更新您的架构。如果 composer 更新后发生错误!

      bin/console doctrine:schema:update --force
      

      【讨论】:

        猜你喜欢
        • 2017-05-01
        • 2012-06-02
        • 2014-03-12
        • 1970-01-01
        • 2012-03-26
        • 1970-01-01
        • 1970-01-01
        • 2012-08-02
        • 2018-10-26
        相关资源
        最近更新 更多