LexikFormFilterBundle KnpPaginationBundle Symfony3

时间:2016-01-15 16:25:19

标签: symfony

分页不包括仅过滤页面参数。

教义内容有效,结果在第一篇文章中过滤, 但是分页不起作用。

是否需要任何其他配置?

我的控制器:

    $qb = $userRepository->createQueryBuilder('product')
        ->andWhere('product.shop = :shop_id')
        ->andWhere("product.uuid != ''")
        ->setParameter("shop_id", $selectedShop->getUid())
        ->orderBy('product.uid', 'ASC');

    $form = $this->createForm(SearchType::class);
    if ($request->isMethod('POST')) {

        $form->handleRequest($request);

        $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
    }

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $query = $qb->getQuery(),
        $request->query->getInt('page', 1),
        15
    );


    return array(
        'pagination' => $pagination,
        'form' => $form->createView()
    );

我的SearchFormType:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('term', TextFilterType::class, array(
            'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                if (empty($values['value'])) {
                    return null;
                }

                $filterQuery->getQueryBuilder()
                    ->andWhere("
                        to long ...
                    ");
            })
        );
}

public function getName()
{
    return 'item_filter';
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'csrf_protection'   => false
    ));
}

0 个答案:

没有答案