我回来了关于我的 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/