New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dinisptc opened this Issue Jul 19, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@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

thanks

@alextech

This comment has been minimized.

Show comment
Hide comment
@alextech

alextech Jul 19, 2016

Contributor

That was been removed in ZF3. All dependencies now must come through constructor. For starters look at https://zendframework.github.io/zend-servicemanager/migration/#factories
Generally:

  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

Contributor

alextech commented Jul 19, 2016

That was been removed in ZF3. All dependencies now must come through constructor. For starters look at https://zendframework.github.io/zend-servicemanager/migration/#factories
Generally:

  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

@albanx

This comment has been minimized.

Show comment
Hide comment
@albanx

albanx Aug 5, 2016

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

albanx commented Aug 5, 2016

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

@alextech

This comment has been minimized.

Show comment
Hide comment
@alextech

alextech Aug 5, 2016

Contributor

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.

Contributor

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.

@alextech

This comment has been minimized.

Show comment
Hide comment
@alextech

alextech Aug 6, 2016

Contributor

As promissed, see if this example helps: https://github.com/alextech/zendframework-tutorial-en/tree/3.1-SM-MVC_Controller. Top 3 commits show stages of migration.

And explanation at https://www.youtube.com/watch?v=15enXq3p7aE

Contributor

alextech commented Aug 6, 2016

As promissed, see if this example helps: https://github.com/alextech/zendframework-tutorial-en/tree/3.1-SM-MVC_Controller. Top 3 commits show stages of migration.

And explanation at https://www.youtube.com/watch?v=15enXq3p7aE

@weierophinney

This comment has been minimized.

Show comment
Hide comment
Member

weierophinney commented Aug 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment