I have a problem. I've got a participant class wich is equivalent to user. The thing is, when I show the list of participants, I do it in a special way, by showing only 20 participants at a time instead of the whole list. I use a variable page that tells me what page is that I have to show, and I use it for calculate the offset from which to show. The problem is that is not showing me the users or just show me some of them. Also I count the total users in the same action but the number doesn't match with the real users. The code that I use in the controller is:
- Code: Select all
/**
* Lists all Participante entities.
*
* @Route("/list/{pag}", requirements={"pag" = "\d+"}, defaults={"pag" = 1})", name="participante_list")
* @Template()
*/
public function indexAction($pag)
{
$repository = $this->getDoctrine()->getRepository('NeodirectorioPhenixBundle:Participante');
$offset=(($pag-1)*20)+1;
$qb=$repository->createQueryBuilder('participantes');
$qb->add('select', 'p')
->add('from', 'NeodirectorioPhenixBundle:Participante p')
->add('orderBy', 'p.nickname ASC')
->setFirstResult( $offset )
->setMaxResults(20);
$entities=$qb->getQuery()->getResult();
$qb1 = $repository->createQueryBuilder('cantidad');
$qb1->select('count(p.id)');
$qb1->from('NeodirectorioPhenixBundle:Participante','p');
$count = $qb1->getQuery()->getSingleScalarResult();
return array(
'entities' => $entities,
'cant' => $count
);
}
