使用symfony2和doctrine获取"无法刷新用户"错误

Ran*_*ngh 6 php symfony doctrine-orm

我将类User作为基类,然后我从用户类扩展了Teacher.

当我尝试登录时,我收到此错误

您无法从不包含标识符的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,
        ));
    }
Run Code Online (Sandbox Code Playgroud)

我无法找到我可以检查错误的位置.我卡住了.请帮忙

ipp*_*ppi 8

"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."
Run Code Online (Sandbox Code Playgroud)

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

如果从数据库中删除当前用户,然后尝试重定向用户,则会出现此错误.(这似乎是一个愚蠢的错误,但错误信息肯定没有帮助!)解决方案是在重定向之前简单地清除会话.

$this->get('security.context')->setToken(null);
$this->get('request')->getSession()->invalidate();
Run Code Online (Sandbox Code Playgroud)


Mun*_*Das 5

代码EntityUserProvider.php你似乎必须序列id还可以根据用户的。