如何从存储库中访问上下文用户(即:$ this-> getUser())?
类似的东西:
public function findInviteRequestByUser(\Fundacity\UserBundle\Entity\User $user)
{
$contextUser = $this->getUser();
...
// HERE GOES THE QUERY
...
return $query->getResult();
}
答案 0 :(得分:0)
您应该将安全上下文作为参数传递 你的控制器
$securityContext = $this->get('security.context');
$em->getRepository('YourBundle')->findInviteRequestByUser($securityContext);
您的实体存储库
public function findInviteRequestByUser(\Symfony\Component\Security\Core\SecurityContext $context)
{
$user = $context->getToken()->getUser();
...
}