0

我在 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;

所以当我尝试加载我的页面时,我收到了这个错误:

在此处输入图像描述

4

2 回答 2

2

调用操作时必须通过 Request 类:

public function offerAction(Request $request, User $user, $archive = false)
{
    return $this->resultsAction($request, $user, Operation::OFFER, $archive);
}
于 2017-09-12T13:22:56.407 回答
1

您忘记将 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);
}
于 2017-09-12T13:19:03.100 回答