Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 2.1带KNP Paginator包的ajax过滤器_Ajax_Pagination_Symfony 2.1 - Fatal编程技术网

Symfony 2.1带KNP Paginator包的ajax过滤器

Symfony 2.1带KNP Paginator包的ajax过滤器,ajax,pagination,symfony-2.1,Ajax,Pagination,Symfony 2.1,您好,我有一个页面,其中有一个包含元素列表的表(index.html.twig.)。我使用KNP Paginator Bundle对结果进行分页。现在我想在这个页面中实现一些过滤器来过滤表结果。我使用AJAX来实现这一点,因此我创建了另一个视图(grupos.html.twig),其中包含表和分页器,以呈现查询结果。 以下是控制器代码: public function filtrarGrupoPorLetraAction(){ if ($this->getRequest()->is

您好,我有一个页面,其中有一个包含元素列表的表(index.html.twig.)。我使用KNP Paginator Bundle对结果进行分页。现在我想在这个页面中实现一些过滤器来过滤表结果。我使用AJAX来实现这一点,因此我创建了另一个视图(grupos.html.twig),其中包含表和分页器,以呈现查询结果。 以下是控制器代码:

public function filtrarGrupoPorLetraAction(){
 if ($this->getRequest()->isXmlHttpRequest()) {
   $em = $this->getDoctrine()->getManager();
   $letra = $this->getRequest()->get('letra');
   $entities = $em->getRepository('GrupoBundle:Grupo')->filtrar($letra);

   $paginator = $this->get('knp_paginator');
   $pagination = $paginator->paginate(
     $entities,
     $this->get('request')->query->get('page', 1) /*page number*/,
     25/*limit per page*/
   );

   return $this->render('GrupoBundle:Grupo:grupos.html.twig', compact('pagination'));
 }
}
但是这段代码呈现一个新页面,我想将结果传递到index.html.twig以呈现一个div


我该怎么做呢?

如果您只需要一个json响应,请使用下面的代码

// create a JSON-response with a 200 status code
$response = new Response(json_encode($yourData));
$response->headers->set('Content-Type', 'application/json');

return $response;
如果需要渲染模板

return $this->renderView('YourTemplateFile', $yourParams);

希望这有助于将结果数据附加到div中