如何显示并同时可以在symfony2中搜索?

时间:2015-08-07 07:35:46

标签: php symfony

我正在使用symfony2进行项目。我有一个搜索功能,分页,同时只在一个存储库功能中显示所有事务。一切正常,直到我发现,每当我转到我网站的其他标签并再次返回我的轨道页面时,它返回我"没有找到结果"而不是显示所有交易。但是,当我单击搜索按钮时,它再次显示所有事务,但是再次,当我单击分页按钮时,它再次返回我没有找到结果。我认为我的代码确实存在冲突。我不知道它在哪里。我希望有人可以帮助我。

这是我的存储库代码:

public function getAllTransaction($rNumber,$startDate,$endDate,$gNumber,$senderId,$receiverId,$docType,$direction,$page = 1, $limit = 10) {
         $em = $this->getEntityManager();
         $query = $em->createQuery(
           'SELECT partial a.{supplierTransactionDetailId, rNumber, pNumber, invNumber, anNumber, adNumber, amount}, 
            partial b.{supplierTransactionId, transactionDate, senderId, receiverId, isaNumber, gsNumber, fileName}, 
            partial c.{supplierDocTypeId, docType, direction} 
            FROM SupplierBundle:SupplierTransactionDetail a 
            JOIN a.supplierTransaction b 
            JOIN b.supplierDocType c
            WHERE (a.rNumber LIKE :rNumber OR a.pNumber LIKE :rNumber 
                  OR a.invNumber LIKE :rNumber 
                  OR a.anNumber LIKE :rNumber 
                  OR a.adNumber LIKE :rNumber )
            AND ((:startDate = \'\' OR :endDate = \'\') OR 
          (b.transactionDate BETWEEN :startDate AND :endDate))
            AND b.gsNumber LIKE :gsNumber
            AND b.senderId LIKE :senderId
            AND b.receiverId LIKE :receiverId
            AND c.docType LIKE :docType
            AND c.direction LIKE :direction


            ORDER BY b.transactionDate desc'
          )
          ->setParameter('rNumber', $rNumber)
          ->setParameter('startDate', $startDate)
          ->setParameter('endDate', $endDate)
          ->setParameter('gsNumber', $gsNumber)
          ->setParameter('senderId', $senderId)
          ->setParameter('receiverId' , $receiverId)
          ->setParameter('docType',$docType)
          ->setParameter('direction', $direction)
          ->setFirstResult(($page - 1) *$limit )
          ->setMaxResults($limit);

         $paginator = new Paginator ($query, $fetchJoinCollection = false );
         $paginator->setUseOutputWalkers(false);

         return $paginator;
      }

更新

控制器

public function trackAction(Request $request,$page){
        $rNumber = $request->query->get('rNumber');
        $gsNumber = $request->query->get('gsNumber');
        $senderId = $request->query->get('senderId');
        $receiverId = $request->query->get('receiverId');
        $docType = $request->query->get('docType');
        $direction = $request->query->get('direction');
        $startDate = $request->query->get('startDate');
        $endDate = $request->query->get('endDate');

        $max_records = 10;
        $em = $this->getDoctrine()->getManager();
        $trans = $em->getRepository('SupplierBundle:SupplierTransactionDetail')->getAllTransaction($rNumber,$gsNumber,$senderId,$receiverId,$docType,$direction,$startDate,$endDate,$page , 10);

        $count = $trans->count();
        $pagination = array(
            'page' => $page,
            'route' => 'supplier_tracking',
            'route_params' => array()
        );

        if ($max_records > 0 ){
            $pagination['pages_count'] = max(ceil($count / $max_records), 1);
        }

        return $this->render('SupplierBundle:Supplier:tracking.html.twig',array('trans' => $trans, 'pagination' => $pagination));


    }

更新

supplier_tracking:
    pattern: /track/{page}
    defaults: { _controller: "SupplierBundle:Supplier:track" , page: 1 }

2 个答案:

答案 0 :(得分:0)

您的网址不同: /track?match=all&refNumber=&direction=&docType=&startDate=&senderId=&endDate=&gsNumber=&receiverId=&submit= 上面显示了所有需要的参数,但是当你回去时

track/2

是您的网址,您缺少所需的所有参数。

在您的背部功能中,您无法提供所有必需的参数

答案 1 :(得分:0)

只需在模板中定义form方法并将其设置为“get”或从标记中删除此属性(方法)。