工厂没有被加载ZF2 - 缺少参数1

问题描述:

我有内Module/src/Module/Service/Factory/CourseServiceFactory.php工厂没有被加载ZF2 - 缺少参数1

工厂我在module.config.php如下定义的这家工厂:

'service_manager' => array(
     'factories' => array(
      'CourseServiceFactory' => 'Module\Service\Factory\CourseServiceFactory', 
     ), 
), 

但是这家工厂没有被调用时加载该应用程序,我收到此错误:

Warning: Missing argument 1 for Module\Service\CourseService::__construct(),

这是怎么我的CourseServiceFactory.php看起来像:

public function createService(ServiceLocatorInterface $serviceLocator) 
{ 
    $config = $serviceLocator->get('config'); 

    return new CourseService($config); 
} 

任何人都知道什么是错的?

+1

如何调用服务定位器是什么样子? – akond

+0

什么是你的__constructor(), Module \ Service \ CourseService :: __ construct(), –

+0

@akond的参数我很抱歉你打电话给服务定位器是什么意思?一旦你在module.config.php中定义它们,工厂就不会加载Bootstrap了吗? –

我怀疑你没有实现工厂接口,导致服务加载器被注入构造函数。

确保您的工厂工具:

的Zend \的ServiceManager \ FactoryInterface

见例如工厂里

https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html

+0

我在工厂实施工厂界面 –

+0

可以发布完整的工厂代码吗 – Andrew