简体   繁体   中英

Factory not being loaded in ZF2 - Missing argument 1

I have a factory within Module/src/Module/Service/Factory/CourseServiceFactory.php

I have defined this factory in module.config.php as follows:

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

However this factory isn't being loaded upon calling the application and I receive this error:

: Missing argument 1 for Module\\Service\\CourseService::__construct(), :缺少Module \\ Service \\ CourseService :: __ construct()的参数1,

This is how my CourseServiceFactory.php looks like:

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

    return new CourseService($config);
}

Anyone have any idea what's wrong?

I suspect you're not implementing the factory interface which causes the service loader to be injected into the constructor.

Make sure your factory implements:

Zend\\ServiceManager\\FactoryInterface

See example factory here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM