0

我正在为 symfony 3 中的作业开发 Web 应用程序,我需要显示一个表格,并且我需要该表格仅显示 5 个结果,并使用 knppaginator 对列进行排序。我使用以下代码:

$em = $this->getDoctrine()->getManager()->createQueryBuilder(); 
    $dql = $em
    ->select( 'w.id, c.nombre AS Cliente, u.nombre AS  Usuario, w.titulo AS Titulo, w.descripcion AS Descripcion, w.fecharegistro AS FechaRegistro, w.fechainicio AS FechaInicio, w.fechaentrega AS FechaEntrega, w.prioridad AS prioridad, w.terminado AS terminado')
    ->add('from','ClientBundle:Client c')
    ->innerJoin('WorkBundle:Work', 'w', 'WITH', 'c.id=w.iDCliente')
    ->innerJoin('UserBundle:User', 'u', 'WITH', 'w.iDUsuario=u.id')
    ->where('w.terminado=0 and u.nombre= :name')->setParameter('name',$session->get('name'))
    ->getQuery();
    $works = $dql->getResult();


 $paginator = $this->get('knp_paginator');

        $pagination = $paginator->paginate($works, $request->query->getInt('page',1),5);

    return $this->render("UserBundle:User:main.html.twig",array("vacio"=>$works,"fechaActual"=>$fechaActual,"name"=>$session->get("name"),"pagination"=>$pagination));

如果我不使用“getResult()”,则分页器直接获取查询,因此 knppaginator 可以对列进行排序但不能对它们进行分页,但是如果我使用“getResult()”方法,则表格正确分页但表格不能排序的

4

0 回答 0