chicken burger
chicken burger

Reputation: 774

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.

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:

enter image description here

Upvotes: 0

Views: 100

Answers (2)

Imanali Mamadiev
Imanali Mamadiev

Reputation: 2654

You have to pass Request class when you call action:

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

Upvotes: 2

svgrafov
svgrafov

Reputation: 2014

You forgot to add Request argument into ResultsAction call.

Declaration contains 4 arguments:

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

Call contains 3:

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

Upvotes: 1

Related Questions