切换到另一页面后删除过滤器设置knp_pagination

时间:2018-07-03 09:22:25

标签: php symfony session pagination symfony-3.3

切换到另一页后删除过滤器设置

我认为我需要在会话中写"$ data = $ form-> getData ();",然后从那里开始

还是还有其他解决方案?

  

如何解决?

有2个文件

  

“ EquipementsController”

<?php

    namespace AdminBundle\Controller;

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpFoundation\Request;

    use Symfony\Bridge\Doctrine\Form\Type\EntityType;

    use Symfony\Component\Form\Extension\Core\Type\EmailType;
    use Symfony\Component\Form\Extension\Core\Type\SubmitType;
    use Symfony\Component\Form\Extension\Core\Type\TextareaType;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

    use Symfony\Component\Form\Extension\Core\Type\ChoiceType;


    use Symfony\Component\Validator\Constraints as Assert;

    use AdminBundle\Entity\Equipments;

    use AdminBundle\Repository\Metier;



class EquipementsController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */



    public function indexAction(Request $request)
    {


            $metiers = $this->getDoctrine()->getManager()->getRepository('AdminBundle:Metier')->getForSearch();


            $form = $this->createFormBuilder()

                    ->add('metier', ChoiceType::class, array('choices' => $metiers, 'required' => true, 'placeholder' => 'Tous', 'multiple' => true, 'expanded' => true,  'label' => false, 'empty_data' => function() {
                return ['checked' => 'checked'];
            }
                    //->add('metier', EntityType::class, array('class' => 'AdminBundle:Metier', 'choice_label' => 'name','required' => false, 'expanded' => true,  'placeholder' => 'Tous', 'multiple' => true, 

            ))



                    ->add('operation', EntityType::class, array('class' => 'AdminBundle:Operation', 'choice_label' => 'name', 'label' => false, 'required' => true, 'expanded' => true,  'placeholder' => 'Tous', 'multiple' => true,'empty_data' => function() {
                return ['checked' => 'checked'];
            }
            ))

                    ->add('search', TextType::class, array('required' => false,  'label'       => "MOT CLEF "))

                     ->add('submit', SubmitType::class, [
                         'label' => "VALIDER VOTRE RECHERCHE",
                     ])
                     ->getForm()
        ;

        $form->handleRequest($request);

          if($form->isSubmitted() &&  $form->isValid()){

           $data = $form->getData(); 

       $repository=$this
       ->getDoctrine()
       ->getManager()
       ->getRepository('AdminBundle:Equipments');

       $listequipments=$repository->ListAll($data);

         $paginator  = $this->get('knp_paginator');

        $pagination = $paginator->paginate(
        $listequipments, /* query NOT result */
        $request->query->getInt('page', 1)/*page number*/,
        1000/*limit per page*/
        );

       return $this->render('AdminBundle:Advert:equipements-drupal.html.twig', array('pagination' => $pagination,'form'=>$form->createView()));

    }

    // index3.html.twig, c'est la version de base avec tous les logos

    $data = null;

    $repository=$this
       ->getDoctrine()
       ->getManager()
       ->getRepository('AdminBundle:Equipments');

       $listequipments=$repository->ListAll($data);


        $paginator  = $this->get('knp_paginator');

        $pagination = $paginator->paginate(
        $listequipments, /* query NOT result */
        $request->query->getInt('page', 1)/*page number*/,
        10/*limit per page*/
        );

       return $this->render('AdminBundle:Advert:equipements-drupal.html.twig', array('pagination' => $pagination, 'form'=>$form->createView()));

    }

}
  

和“存储库设备”

<?php

namespace AdminBundle\Repository;



/**
 * EquipmentsRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */

class EquipmentsRepository extends \Doctrine\ORM\EntityRepository
{


    public function ListAll($data)
    {

        $query = $this->createQueryBuilder('b')->orderBy('b.updated','DESC');


        if($data['metier'] != '')
{
$query->innerJoin('b.metier', 'met')->andWhere('met.id IN (:metids)')->setParameter('metids', $data['metier']);
//$query->innerJoin('b.metier', 'met')->andWhere('met.id = :metid')->setParameter('metid', $data['metier']);


}

                if($data['operation'] != '')
{
$query->innerJoin('b.operation', 'ope')->andWhere('ope.id IN (:opeids)')->setParameter('opeids', $data['operation']);

}



        if($data['search'] != '')
{
    $query->andWhere('b.name LIKE :searchTerm OR b.description LIKE :searchTerm')->setParameter('searchTerm', '%'.$data['search'].'%');
    //->orWhere('b.description LIKE :description')->setParameter('description', '%'.$data['search'].'%');

}       



        return $query->getQuery()->getResult();


    }



}

我假设未保存会话数据,但是可能是什么问题呢?我在做什么错了?

0 个答案:

没有答案