我想通过pagerfanta呈现的分页链接与表单数据一起提交。 这是考虑在搜索表单中输入的数据。
简单的分页链接不允许我在搜索结果中导航。 有什么帮助吗?
控制器
/**
* @Route("/{page}/", name="admin_user",requirements={"page" = "\d+"}, defaults={"page" = 1})
* @Template()
*/
public function indexAction($page = 1)
{
$data = [];
$data['name'] = $this->getUser()->getName();
$form = $this->createForm('admin_user_search_type', null);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bind($request);
$data = array_merge($data, $form->getData());
}
return $this->render('AABundle:User:index.html.twig', array(
'pager' => $this->getDoctrine()->getManager()->getRepoitory('AABundle:User')->search($data, 4, $page, $this->getUser()),
'form' => $form->createView(),
));
}
view.html.twig
{% if pager.haveToPaginate %}
{{ pagerfanta(pager, 'twitter_bootstrap3') }}
{% endif %}
答案 0 :(得分:0)
解决方案是使用Get method而不是Post提交表单以便能够检索表单数据。我们也不需要检查是否有效,而它是一个搜索表单。
控制器如下所示:
**
* @Route("/{page}/", name="admin_user",requirements={"page" = "\d+"}, defaults={"page" = 1})
* @Template()
*/
public function indexAction($page = 1)
{
$data = [];
$data['name'] = $this->getUser()->getName();
$form = $this->createForm('admin_user_search_type', null);
$request = $this->getRequest();
$form->bind($request);
$data = array_merge($data, $form->getData());
return $this->render('AABundle:User:index.html.twig', array(
'pager' => $this->getDoctrine()->getManager()->getRepoitory('AABundle:User')->search($data, 4, $page, $this->getUser()),
'form' => $form->createView(),
));
}
form.html.twig
<form name= "search" action="{{ path('admin_user') }}" novalidate method="get"{{ form_enctype(form) }}>
</form>