Hello,
I’m migrating quite a big project from ZF2 to Laminas and I’m nearly there.
In the older version, I have an EmailModel which is accessed by various different controllers in order to send emails, with variables like ‘account name’ @ ‘domain name’ from the config files, which used to be accessed using the ServiceManager with a line like $config = $this->getServiceLocator()->get(‘Configuration’); within the EmailModel.
What is the best way to replace this?
I’ve got all the Controllers working with Factories, that inject the Doctrine Entity manager and the Config into the Controllers when instantiated. The Factory system seems dedicated to Controllers, not Models, and I can’t figure out how to configure the Class’ module.config.php file to replicate the controller injection facility like:
'controllers' => [
'factories' => [
Controller\EmailController::class => Factory\EmailControllerFactory::class
],
],
Things like the following doesn’t work:
'controllers' => [
'factories' => [
Controller\EmailController::class => Factory\EmailControllerFactory::class,
Model\EmailModel::class => Factory\EmailModelFactory::class,
],
],
And this doesn’t work either:
'service_manager' => [
'factories' => [
Model\EmailModel::class => Factory\EmailModelFactory::class,
],
],
I’d be grateful if someone could tell me either how to inject dependencies into Models, or whether this is completely the wrong approach, and I should be passing the Config variables into the Model as arguments when they are created in a Controller?
I hope that my question makes sense. Thank you,
Tom