I'm new in ZendFramework3 and I just want to know if it's possible to call a function with more arguments than just the serviceManager in factories (within my Module class) : (Is it possible to pass an argument next to the $sm argument?)
//class Module
//getConfig()
//getServiceConfig()
public function getControllerConfig()
{
return [
'factories' => [
Controller\ModuleController::class => function ($sm) {
return new ModuleController($sm);
}
]
];
}
You may (for sure) pass other Arguments to Factory, so long as the Class to be created can handle the Arguments gracefully. In the example below, a Factory Class was created inside the Controller Directory. This is now the factory- ModuleControllerFactory - that instantiates the ModuleController.
So, now we can create the Constructor of the ModuleController Class:
And now, update the
module.config.phpinside the config Folder of your module Example:module/Application/config/module.config.php.