Symfony2 custom Voter: cannot have access to getDoctrine from inside the Voter
I solved it. This is pretty curious: I spend hours or days on a problem, then post a question here, and I solve it myself within an hour :/
I needed to add the following in my voter class:
public function __construct(EntityManager $em){ $this->em = $em;}
I needed to add the following on top:
use Doctrine\ORM\EntityManager;
I also needed to add the arguments in the service.yml
security.access.project_voter: class: AppBundle\Security\Authorization\Voter\ProjectVoter arguments: [ @doctrine.orm.entity_manager ] public: false tags: - { name: security.voter }