我有这个Paginator类构造函数:
class Paginator { public function __construct($total_count,$per_page,$current_page) { } }
Paginator服务在Ibw / JobeetBundle / Resources / config / services.yml中注册,如下所示:
parameters: ibw_jobeet_paginator.class: Ibw\JobeetBundle\Utils\Paginator services: ibw_jobeet_paginator: class: %ibw_jobeet_paginator.class%
当我像这样使用Paginator时:
$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,$current_page);
我得到这个例外:
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
好吧,要回答你的问题,你使用arguments参数传递服务构造函数参数:
services: ibw_jobeet_paginator: class: %ibw_jobeet_paginator.class% arguments: - 1 # total - 2 # per page - 3 # current page
当然,由于参数是动态的,因此并没有真正帮助你.
class Paginator { public function __construct() {} public function init($total_count,$current_page) { } } $paginator = $this->get('ibw_jobeet_paginator')->init($total_jobs,$current_page);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。