Skip to content
This repository has been archived by the owner. It is now read-only.

A plugin by the name "getServiceLocator" was not found in the plugin manager Zend\Mvc\Controller\PluginManager #369

dinisptc opened this issue Jul 19, 2016 · 5 comments


Copy link

@dinisptc dinisptc commented Jul 19, 2016

A plugin by the name "getServiceLocator" was not found in the plugin manager Zend\Mvc\Controller\PluginManager

i have modules from zf2 to zf3

i am having this error with the getServiceLocator:

$this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');

i am using getServiceLocator all over the module
for translator also

i cannot find a good tutorial to upgrade this to zf3


Copy link

@alextech alextech commented Jul 19, 2016

That was been removed in ZF3. All dependencies now must come through constructor. For starters look at

  1. whatever you are looking for in getServiceLocator move to that controller's constructor parameter. Create constructor if there is not one already and assign parameters to private property so that all actions can access them.
  2. Where you have controller defined, probably in route somewhere, (I will guess it is now most likely created as an invokable), switch it to a factory.
  3. Factory can either be an anonymous function taking in same parameters as described in the linked page, or create a whole factory class and point to it. For quick migration anonymous function is easiest.
  4. Whether you pick anon. function or full class, first parameter ServiceLocatorInterface $serviceLocator can be used to get->('name of service'). Take that and...
  5. create new instance of controller class with parameters taken from 4 and return it.

BTW, if you are using DoctrineORMModule it is not fully migrated to MVC yet, but its not too horrible to create as a service manually

Copy link

@albanx albanx commented Aug 5, 2016

What about adding an example to the current skeleton with a service example?

Copy link

@alextech alextech commented Aug 5, 2016

That will unfortunately be beyond purpose of skeleton because there are too many different case specific ways to do this. I got a video tutorial in production due out today or tomorrow on this subject of service manager, that will also have a link to tutorial repository extending this skeleton repository with just that. I will add a section for controller dependency management, which I forgot about.

Copy link

@alextech alextech commented Aug 6, 2016

As promissed, see if this example helps: Top 3 commits show stages of migration.

And explanation at

Copy link

@weierophinney weierophinney commented Aug 16, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.