简体   繁体   English

在带有奇怪控制器的symfony 2.3上使用Knp分页器

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

I'm using Knp paginator on a symfony 2.3 project and the project is new to me so the controllers are a bit odd to use. 我在symfony 2.3项目上使用Knp分页器,而该项目对我来说是新项目,因此使用控制器有些奇怪。

I'm trying to install it but there is things that still blocks from making it functioning. 我正在尝试安装它,但仍有一些使它无法正常运行的功能。

I'm following this tutorial actually 实际上正在按照本教程

and here is my code in my controller 这是我的控制器中的代码

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);
}

My namespace and class using: 我的命名空间和类使用:

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;

And so when I try to load my page I get this error: 因此,当我尝试加载页面时,出现以下错误:

在此处输入图片说明

You have to pass Request class when you call action: 调用操作时,您必须传递Request类:

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

You forgot to add Request argument into ResultsAction call. 您忘记将Request参数添加到ResultsAction调用中。

Declaration contains 4 arguments: 声明包含4个参数:

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

Call contains 3: 通话包含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