【发布时间】:2014-10-28 16:51:47
【问题描述】:
我希望 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 %}
【问题讨论】:
-
您可以将表单数据存储在Session中,测试是否存在,并将这些数据用作过滤器。
-
解决方法是在提交表单时使用Get方法
标签: symfony pagerfanta