symfony - FOS UserBundle 无法登录

标签 symfony doctrine-orm fosuserbundle

我回来了关于我的 UserBundle 的另一个问题:
通过 Symfony2 安装和配置 FOS 包时,一切都很完美,它甚至让我创建了 2 个正确插入到我的数据库中的用户。

但是,每次我尝试登录这些帐户中的任何一个时,都会收到以下错误

Warning: Erroneous data format for unserializing 'VillaPrivee\UserBundle\Entity\User' in /Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869

这就是第 869 行所指的内容:
/**
     * Creates a new instance of the mapped class, without invoking the constructor.
     *
     * @return object
     */
    public function newInstance()
    {
        if ($this->_prototype === null) {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }

        return clone $this->_prototype;
    }

这是我的用户实体:
namespace VillaPrivee\UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

不确定我做错了什么,因为我只是按照分步文档安装了整个东西......
谢谢大家帮助

最佳答案

如果您使用的是 PHP 版本 5.4.29 或 5.5.13

在:“/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php ”中找到函数“newInstance”(在第827行附近)并按如下方式进行编辑,直到修复被学说合并。

public function newInstance()
{
    if ($this->_prototype === null) {
        // $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
            $this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
        } else {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }
    }
    return clone $this->_prototype;
}

@Benji:感谢提示:https://github.com/symfony/symfony/issues/11056

关于symfony - FOS UserBundle 无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24031048/

相关文章:

php - 学说迁移 2 + zend 框架 2 = 可能吗?

symfony - 如何覆盖注册表 FosUser 和选择字段填充角色 SYMFONY2

symfony - 扩展 FOS UserBundle 的 UserProvider

php - Symfony 表单错误信息参数使用

php - 如何在 Symfony2 中使用实体表单字段类型和 JUI 自动完成功能?

php - Doctrine 选择多个对象

php - Doctrine 不映射来自 FOSUserBundle User 类的字段

symfony - 如何使用 Symfony Serializer 反序列化通过提升属性在构造函数上声明的嵌套对象数组?

Symfony2 FOSUserBundle 用户实体字段覆盖

mysql - symfony2/doctrine2 dql 其中字段不正确