如何在 Doctrine 中使用 orWhere | Return 位用户拥有 ROLE_ADMIN 和 ROLE_USER

How to use orWhere in Doctrine | Return user who have ROLE_ADMIN and ROLE_USER

我想 return 有 ROLE_ADMINROLE_USER

的用户

我在存储库中这样做了:

return $this->createQueryBuilder('u')
        ->where('u.roles IN (:val)')
        ->setParameter('val','["ROLE_ADMIN","ROLE_USER"]')
        ->getQuery()
        ->getResult();

但什么都没有 returned... 如何解决这个问题?

ps: I have a user with ROLES : ROLE_ADMIN and ROLE_USER

在 Doctrine 2 中使用 orWhere:

return $this->createQueryBuilder('u')
        ->where('u.roles LIKE :val')
        ->setParameter('val','%ROLE_ADMIN%')
        ->orWhere('u.roles LIKE :val2')
        ->setParameter('val2', '%ROLE_USER%')
        ->getQuery()
        ->getResult();

你也可以这样使用:

return $this->createQueryBuilder('u')
        ->where('u.roles LIKE :val')
        ->orWhere('u.roles LIKE :val2')
        ->setParameters(array('val2' => '%ROLE_USER%', 'val' => '%ROLE_ADMIN%'))
        ->getQuery()
        ->getResult();