簡體   English   中英

在帶有奇怪控制器的symfony 2.3上使用Knp分頁器

[英]Using Knp paginator on symfony 2.3 with weird controller

我在symfony 2.3項目上使用Knp分頁器,而該項目對我來說是新項目,因此使用控制器有些奇怪。

我正在嘗試安裝它,但仍有一些使它無法正常運行的功能。

實際上正在按照本教程

這是我的控制器中的代碼

private function resultsAction(Request $request, User $user, $type, $archive)
{
     $em = $this->getDoctrine()->getManager();

     $results = $em->getRepository("randomRepo")->findByTypeAndPro($type, $user, $archive);

     /**
      * @var $paginator \Knp\Component\Pager\Paginator
      */
     $paginator = $this->get('knp_paginator');
     $results = $paginator->paginate(
         $results,
         $request->query->getInt('page',1),
         $request->query->getInt('limit',5)
     );


     return array("results" => $results, "archive" => $archive);
}

public function offerAction(User $user, $archive = false)
{
     return $this->resultsAction($user, Operation::OFFER, $archive);
}

我的命名空間和類使用:

namespace ST\BackofficeBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use ST\UserBundle\Entity\Operation;
use ST\UserBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

因此,當我嘗試加載頁面時,出現以下錯誤:

在此處輸入圖片說明

調用操作時,您必須傳遞Request類:

public function offerAction(Request $request, User $user, $archive = false)
{
    return $this->resultsAction($request, $user, Operation::OFFER, $archive);
}

您忘記將Request參數添加到ResultsAction調用中。

聲明包含4個參數:

resultsAction(Request $request, User $user, $type, $archive)

通話包含3:

public function offerAction(User $user, $archive = false)
{
    return $this->resultsAction($user, Operation::OFFER, $archive);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM