我有一个搜索栏,可以按名称查找分子,然后在同一页面的搜索栏下方显示包含该名称的所有分子。
我已经添加knpPaginator
并且它运行良好,但是当我进入下一页时,我必须重新加载表单,它会显示下一个分子。
我的问题是:有没有办法避免重新加载表单?我可以在另一个页面中显示结果,但我更愿意保持这样:
$form = $this->createForm('NcstoxBundle\Form\FindMolNameType');
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
$molecules = $em->getRepository('NcstoxBundle:Molecule')->findAll();
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$molecules = $em->getRepository('NcstoxBundle:Molecule')->findByMolName($data);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$molecules, /* query NOT result */
$this->get('request')->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
);
return $this->render('NcstoxBundle:Default:molNameResult.html.twig', array(
'form' => $form->createView(),
'molecules' => $molecules,
'pagination' => $pagination
));
}
我的观点 :
<div class="search">
<h3>Make a Search by Molecule Name :</h3>
{{ form_start(form) }}
{{ form_widget(form, {'attr': {'title': 'test'}}) }}
<input class="btn btn-primary" type="submit" value="Search">
{{ form_end(form) }}
</div>
<h3>Search Results :</h3>
<div class="count">
{{ pagination.getTotalItemCount }} Molecules
</div>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>{{ knp_pagination_sortable(pagination, 'Name', 'a.name') }}</th>
</tr>
</thead>
<tbody>
{% for molecule in pagination %}
<tr>
<td><a href="{{ path('molSheet', {'id':molecule.id}) }}">{{ molecule.mainName }}</a></td>
</tr>
{% else %}
<tr>
<td>There isn't molecule corresponding to your query</td>
</tr>
{% endfor %}
</tbody>
<tfoot></tfoot>
</table>
<div class="navigation fin taille">
{{ knp_pagination_render(pagination) }}
</div>
请放纵一下,StackOverflow 说我有被阻止的危险,而且我是法语,所以英语不是我的主要语言。