mkjasinski
mkjasinski

Reputation: 3088

Symfony2:FOSUserBundle: get users with limit

I would like to get users added by FOSUserBundle. I can do this:

$userManager = $this->get('fos_user.user_manager');
$users = $userManager->findUsers();

However, I have many users and would like to use limit. How can this be done using FOSUserBundle?

I have a separate query, or you can use the repository for the User entity?

Upvotes: 1

Views: 403

Answers (1)

Ken Hannel
Ken Hannel

Reputation: 2748

The UserManager doesn't have a way to limit the results. I recommend just using the repository and writing your own method. It should be a very simple method, like:

$qb = $this->getEntityManager()->createQueryBuilder();

$qb->select('u');
$qb->from('MyBundle:UserEntity', 'u');

$qb->setMaxResults($limit);

$qb->getQuery()->getResult();

Upvotes: 1

Related Questions