2012-07-20 141 views
5

我有类User作为基类,然后我从用户类扩展了Teacher。使用symfony2和doctrine获取“无法刷新用户”错误

当我尝试登录我得到这个错误

你不能从一个不 包含标识符的EntityUserProvider刷新用户。用户对象必须使用由Doctrine映射的 自己的标识符进行序列化。

我有序列化/反序列化功能user.php的,因为我已经能够适应从FOSUserbundle

public function serialize() 
    { 
     return serialize(array(
      $this->password, 
      $this->salt, 
      $this->usernameCanonical, 
      $this->username, 
      $this->expired, 
      $this->locked, 
      $this->credentialsExpired, 
      $this->enabled, 
     )); 
    } 

我无法找到我在哪里可以检查错误。我被卡住了。请帮忙

回答

4

codeEntityUserProvider.php看来你也要序列化id的用户了。

6
"You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine." 

这不是问题的答案,但如果有人使用上面的错误消息(就像我做的那样),这是最受欢迎的。自从我找到我的解决方案后,我想我会分享。

如果您从数据库中删除当前用户,然后尝试重定向用户,将会出现此错误。 (这可能看起来像一个愚蠢的错误,但错误消息肯定没有帮助!)解决方案是在重定向之前清除会话。

$this->get('security.context')->setToken(null); 
$this->get('request')->getSession()->invalidate(); 
+0

谢谢!我有这个确切的问题;删除用户实体,并尝试重新指向登录页面,并得到上述错误。使用Google错误信息,瞧!登陆这里!你努力为我节省了一吨。 – 2014-01-10 01:19:17

+1

注意:对于Symfony 2.6+,你必须使用'$ this-> get('security.token_storage')'。 – hchr 2016-11-27 09:03:31

0

刚把使用class table inheritance同样的问题,它是通过在id属性设置为private能见度引起的,所以子类无法访问ID,改变这protected解决它。

相关问题