5

こんにちは、要素のリスト(index.html.twig。)を含むテーブルのあるページがあります。KNPPaginatorBundleを使用して結果をページ付けしています。ここで、このページにある種のフィルターを実装して、テーブルの結果をフィルター処理したいと思います。これを行うために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をレンダリングしたいと思います。

これどうやってするの?

4

2 に答える 2

0

結果データを div に追加するだけです

于 2014-01-06T22:17:47.790 に答える
-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;

テンプレートをレンダリングする必要がある場合

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

これが役に立ったことを願っています

于 2013-01-30T15:08:47.543 に答える