ram*_*sdm 5 ajax pagination symfony-2.1
嗨,我的页面有一个包含元素列表的表(index.html.twig.).我正在使用KNP Paginator Bundle对结果进行分页.现在我想在此页面中实现某种过滤器来过滤表格结果.我正在使用AJAX来执行此操作,因此我创建了另一个视图(grupos.html.twig),其中包含表和内部的paginator以呈现查询结果.这是控制器代码:
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'));
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码渲染了一个新页面,我想将结果传递给index.html.twig来渲染一个div.
我怎样才能做到这一点?
Jul*_*lin -1
如果您只需要 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;
Run Code Online (Sandbox Code Playgroud)
如果你需要渲染aa模板
return $this->renderView('YourTemplateFile', $yourParams);
Run Code Online (Sandbox Code Playgroud)
希望这有帮助