0

如何从存储库中访问上下文用户(即:$this->getUser())?

就像是:

public function findInviteRequestByUser(\Fundacity\UserBundle\Entity\User $user)
{
    $contextUser = $this->getUser();   
    ...
    // HERE GOES THE QUERY
    ... 

    return $query->getResult();
}
4

1 回答 1

0

您应该将安全上下文作为参数传递。
你的控制器

$securityContext = $this->get('security.context');
$em->getRepository('YourBundle')->findInviteRequestByUser($securityContext);

您的实体存储库

public function findInviteRequestByUser(\Symfony\Component\Security\Core\SecurityContext $context)
{
    $user = $context->getToken()->getUser();   

    ... 
}
于 2013-07-05T19:18:13.317 回答