I have this Paginator
class constructor:
class Paginator
{
public function __construct($total_count, $per_page, $current_page)
{
}
}
The Paginator
Service is registered in Ibw/JobeetBundle/Resources/config/services.yml
like this :
parameters:
ibw_jobeet_paginator.class: Ibw\JobeetBundle\Utils\Paginator
services:
ibw_jobeet_paginator:
class: %ibw_jobeet_paginator.class%
When i use the Paginator
like this:
$em = $this->getDoctrine()->getManager();
$total_jobs = $em->getRepository('IbwJobeetBundle:Job')->getJobsCount($id);
$per_page = $this->container->getParameter('max_jobs_on_category');
$current_page = $page;
$paginator = $this->get('ibw_jobeet_paginator')->call($total_jobs, $per_page, $current_page);
I get this exception:
Warning: Missing argument 1 for
Ibw\JobeetBundle\Utils\Paginator::__construct(), called in
/var/www/jobeet/app/cache/dev/appDevDebugProjectContainer.php on line
1306 and defined in
/var/www/jobeet/src/Ibw/JobeetBundle/Utils/Paginator.php line 13
I guess there's something wrong in passing arguments to the Paginator
service constructor. Could you tell me, How to pass arguments to a service constructor ?
Best Answer
Well, to answer your question, you pass service constructor arguments using the arguments parameter:
Of course that does not really help you out much since the parameters are dynamic.
Instead, move the arguments from the constructor to another method: