How are you supposed to use the Translator inside the controller, i.e. when you are returning a JsonModel and want to translate error messages? Should there be a controller plugin, or is there another approach that should be taken here?
You could retrieve the translator like this
$translator = $this->getServiceLocator()->get('Translator');
and then translate whatever is needed.
Also see @weierophinney's comments in #4305.
Well, since there is a discusion whether the ServiceLocator actually should be injected into the controllers, I would consider this not the "correct" approach, even though it is what I now wound up doing.
The only problem I see with injecting the dependencies of a controller in the factory is that
Thus, you may have a better design, but a performance penalty because you have to create services that are not needed in a specific case. However, this might result in smaller controllers, with smaller (more dedicated) responsibilities.
Matthew, can you point us to the documentation for these lazy and deferred service types? I would like to find out more about it. Deeply appreciate it!
Ah, I see - right here: #2995.
For those interested, the corresponding PRs are right here:
@localheinz And the URLs to the documentation:
localheinz thanks thanks thanks!!
$translator = $this->getServiceLocator()->get('Translator'); =)