php - ZF3 What to do with getServiceLocator()->get('translator') in AbstractContoller -
i have abstract controller in app (zf3) extends module controllers.
i'm calling here base translator , apply translator per module getservicelocator() removed zf3 i'm wonder can create $this->translator in extended controller.
this used in zf2:
$this->translator = $this->getservicelocator()->get('translator');
i have found these docs seems purpose me.
https://zendframework.github.io/zend-mvc/migration/to-v2-7/#servicelocatoraware-initializers
there different ways overcome problem.
first solution comes in mind, more of quick fix else, inject service locator in every controller. in order that, you'll need inject through constructor , change factory controllers (factories if many of them).
as that, yoou can inject translator rather container (service manager).
initializers indeed way go, might removed later on. rather use delegator. way, not have inject through constructor, you'll need inject through setter, meaning introduce temporal coupling...
Comments
Post a Comment