FOS UserBundle 无法登录 [英] FOS UserBundle Unable to login

查看:14
本文介绍了FOS UserBundle 无法登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm back with another issue regarding my UserBundle : Everything went perfect while installing and configuring FOS bundle through Symfony2, it even let me create 2 users that were properly inserted into my DB.

但是,每次尝试登录这两个帐户时,都会出现以下错误

However, every time I try to login into either of these accounts, I get the following error

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

这就是第 869 行所指的内容:

This is what the line 869 refers to :

/**
     * 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 VillaPriveeUserBundleEntity;

use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;

/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

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

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

Not sure what I did wrong, since I just installed the whole thing following the step by step documentation... Thanks guys for your help

推荐答案

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

If you are using PHP Version 5.4.29 or 5.5.13

在:/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php"中找到函数newInstance"(大约第 827 行)并按如下方式编辑,直到修复由教义合并.

In: "/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php" find function "newInstance" (around Line 827) and edit as followed until the Fix is merged by doctrine.

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

@Benji: thx for the hint: https://github.com/symfony/symfony/issues/11056

这篇关于FOS UserBundle 无法登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆