0

我希望 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 %}
4

1 回答 1

0

解决的办法是用Get方法而不是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>
于 2014-10-28T08:51:47.120 回答