Raj*_*ani 5 authentication mapping symfony
我无法在symfony2中使用'Employee'实体进行身份验证,因为它包含许多与项目中其他实体的映射.我的一些映射如下:
/**
* @var EmployeeDesignation
*
* @ORM\ManyToOne(targetEntity="EmployeeDesignation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="employee_designation_id", referencedColumnName="id")
* })
*/
private $employeeDesignation;
/**
* @var EmployeeDesignation
*
* @ORM\ManyToOne(targetEntity="EmployeeType")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="employee_type_id", referencedColumnName="id")
* })
*/
private $employeeType;
Run Code Online (Sandbox Code Playgroud)
身份验证在没有任何映射的情 我尝试过使用'Serialize()'和'Unserialize()'方法,如下所示:
class Employee implements AdvancedUserInterface, \Serializable {
/**
* serialize the username
* @return serialize
*/
public function serialize() {
return serialize($this->emailOfficial);
}
/**
* unserialize
* @param $data
*/
public function unserialize($data) {
$this->em = unserialize($data);
}
}
Run Code Online (Sandbox Code Playgroud)
执行上述方法后,我收到以下错误:
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)
我试过这种方式,以摆脱以前的错误,如下所示:
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL
Run Code Online (Sandbox Code Playgroud)
那么,任何人都可以建议一种方法来克服这个问题吗?
yvo*_*yer 19
我遇到了类似的事情,经过一些研究,我尝试了和你一样的事情.
但在某些时候,我发现通过设置__sleep
方法,每件事都运行良好.
class User implements PlayerInterface { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; ... public function __sleep() { return array('id'); } ...
@ORM\Id
返回数组的一部分.在设置一个新的关联时,我不知道为什么会导致这种情况(我的是ManyToMany),但它可能来自这个地方:
// see Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse() ... $event->getRequest() ->getSession() ->set('_security_'.$this->contextKey, serialize($token)); ...
希望这可以帮助某人.
编辑:
参考文献:
归档时间: |
|
查看次数: |
5021 次 |
最近记录: |