Commit 0bf52e9b authored by Mat's avatar Mat

le repository corrigé de notre fonction de pagination

parent 26353ba1
......@@ -87,28 +87,20 @@ class MembreRepository extends \Doctrine\ORM\EntityRepository
*/
public function findAllForAPIReadPaginate($paginate, $start, $column = null, $order = null)
{
// $dql = "SELECT m FROM AssoBundle\Entity\Membre m
// ORDER BY m.:column :order LIMIT :start, :paginate ";
// $query = $this->getEntityManager()
// ->createQuery($dql)
// ->setParameters(array(
// ':column' => $column,
// ':order' => $order,
// ':start' => (($start - 1) * $paginate),
// ':paginate' => $paginate
// ));
// return $query->getResult();
//->add('orderBy', new Expr\OrderBy('m.:column', ':order'))
$qb = $this->createQueryBuilder('m');
$qb ->add('orderBy', 'm.:column :order')
->setParameters(array(
':column' => $column,
':order' => $order
));
$qb ->setMaxResults($paginate)
$qb = $this->createQueryBuilder('m')
->join('m.association', 'a')
->addSelect('a')
->setMaxResults($paginate)
->setFirstResult(($start - 1) * $paginate);
if ($column !== null) {
$qb ->orderBy(sprintf('m.%s', $column), $order);
// ou plus simplement 'm.' . $column
}
// Toutes ces méthodes du queryBuilder sont déjà sécurisées.
// Concrêtement on utilise le binding de paramètres (:id)
// principalement pour le where.
return $qb->getQuery()->getResult();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment