我正在创建这样的表单搜索:
当我运行搜索时,它向我显示了包含 10 个元素的第一页,但是当我单击第 2 页时,它显示了我数据库的所有元素,而不考虑我的条件搜索。我不明白
class FrontController extends Controller
{
/**
* @Route("/", name="front_homepage")
*/
public function indexAction(){
$form = $this->createForm(SearchType::class);
return $this->render('FrontBundle::layout.html.twig', array(
'form' => $form->createView(),
));
}
}
class SearchController extends Controller
{
/**
* @param Request $request
* @Route("/search/form", name="front_search_form")
*/
public function searchOffreAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$form = $this->createForm(SearchType::class);
$form->handleRequest($request);
if($form->isSubmitted()) {
$entity = $em->getRepository('CoreBundle:Foo')->findByCritere($form->getData());
/** @var Paginator $paginator */
$paginator = $this->get('knp_paginator');
$result = $paginator->paginate(
$entity,
$request->query->getInt('page', 1),
10
);
return $this->render('FrontBundle:Search:offre.html.twig', ['offres' => $result]);
}
return $this->createNotFoundException();
}
}
谢谢你们,