Security 在symfony身份验证中取消序列化用户数据时出错
我的第一个问题。我在上面坐了几个小时,找不到解决方案: 当用户成功地在数据库中找到时,我猜symfony会尝试将其数据序列化到会话中,错误就会弹出Security 在symfony身份验证中取消序列化用户数据时出错,security,symfony,serialization,offset,Security,Symfony,Serialization,Offset,我的第一个问题。我在上面坐了几个小时,找不到解决方案: 当用户成功地在数据库中找到时,我猜symfony会尝试将其数据序列化到会话中,错误就会弹出 Notice: unserialize(): Error at offset 37 of 49 bytes in G:\cebuland\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\AbstractToken.php line 163
Notice: unserialize(): Error at offset 37 of 49 bytes in G:\cebuland\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\AbstractToken.php line 163
导致登录过程出错
用户实体:
/**
* @ORM\Entity
* @ORM\Table(name="User")
*/
class User implements AdvancedUserInterface, \Serializable{
...
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="user")
* @var $role Doctrine\Common\Collections\ArrayCollection
*/
private $role;
...
public function getRoles() {
return $this->role->toArray();
}
...
public function serialize() {
serialize(array(
$this->id,
$this->name,
$this->password,
$this->created,
$this->last_activity,
$this->ghost,
$this->role
));
}
public function unserialize($serialized) {
list(
$this->id,
$this->name,
$this->password,
$this->created,
$this->last_activity,
$this->ghost,
$this->role
) = unserialize($serialized);
}
角色的实体非常相似
以及security.yml配置文件:
security:
providers:
users:
entity: {class: ApplicationMainBundle:User, property: name}
encoders:
Application\MainBundle\Entity\User:
#plain just for testing
algorithm: plaintext
firewalls:
secured_area:
logout:
path: /logout
pattern: ^/
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
access_control:
- { path: ^/admin/, roles: ROLE_ADMINISTRATOR}
在互联网上找不到任何线索 您的User::serialize方法不返回序列化字符串,但它应该@MarekLewandowski您在这里做了什么使其工作?你能发布一些代码吗?他正在给函数serialize()添加返回