FOS UserBundle无法登录 [英] FOS UserBundle Unable to login
问题描述
通过Symfony2安装和配置FOS包时,一切都很完美,甚至让我创建了正确插入到我的DB中的2个用户。
但是,每次我尝试登录这些帐户之一时,我收到以下错误
警告:在/Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php行中将VillaPrivee\UserBundle\Entity\User取消排序化的错误数据格式869
这是第869行所指的:
/ **
*创建映射类的新实例,而不调用构造函数。
*
* @return对象
* /
public function newInstance()
{
if($ this-> _prototype === null) {
$ this-> _prototype = unserialize(sprintf('O:%d:%s:0:{}',strlen($ this-> name),$ this-> name) );
}
返回克隆$ this-> _prototype;
}
这是我的用户实体:
命名空间VillaPrivee\UserBundle\Entity;
使用FOS\UserBundle\Model\User作为BaseUser;
使用Doctrine\ORM\Mapping作为ORM;
/ **
* @ ORM\Entity
* @ ORM\Table(name =fos_user)
* /
类用户扩展BaseUser
{
/ **
* @ ORM\Id
* @ ORM\Column(type =integer)
* @ ORM\ GeneratedValue(strategy =AUTO)
* /
protected $ id;
public function __construct()
{
parent :: __ construct();
//您自己的逻辑
}
}
不确定我做错了,因为我只是按照一步一步的文件安装了整个事情...
感谢你们的帮助
如果您使用PHP版本5.4.29或5.5.13
In: / vendor / doctrine / orm / lib / Doctrine / ORM / Mapping / ClassMetadataInfo.php find functionnewInstance(在827行左右),然后编辑,直到修正由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-> _prototype;
}
@Benji:thx为提示:https://github.com/symfony/symfony/issues/11056
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 'VillaPrivee\UserBundle\Entity\User' in /Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 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;
}
And this is my User entity :
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
}
}
Not sure what I did wrong, since I just installed the whole thing following the step by step documentation... Thanks guys for your help
If you are using PHP Version 5.4.29 or 5.5.13
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: thx for the hint: https://github.com/symfony/symfony/issues/11056
这篇关于FOS UserBundle无法登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!