Skip to content
Advertisement

Zend Framework 3 : Unable to resolve service as a factory

I already saw many threads about my issue but none of the was able to fix it..

Indeed, I made a factory for my FournitureTable Model and the error returned is :

JavaScript

Here’s the main structure of my module:

JavaScript

FournitureTable.php

JavaScript

FournitureTableFactory.php

JavaScript

module.config.php

JavaScript

I’m new on Zend 3 and StackOverflow so sorry if my explanation are a little consfused.

Also sorry if my English is not perfect, I’m French.

Thank’s in advance !

Advertisement

Answer

You declared the factory under the wrong configuration key.

controllers configuration is meant, as the name suggests, for… controllers. Only the ControllerManager looks inside into that configuration.

The one you are looking for is service_manager, as told in the tutorial.
Actually, in the tutorial they retrieve the configuration through the ConfigProviderInterface methods, but here you’ll find the corresponding array key configuration.

Last two tips:

  • since you are declaring all the classes at the beggining of the file (use ....), there is no need to use the fully qualified name space inside the array
  • try to keep consistence in your structure. You put FournitureTableFactory inside the ModelFactory folder, but the FournitureControllerFactory inside Factory folder. Two factories located in two locations, following two different logics, it doesn’t make a lot of sense 😉

Change your module.config.php with this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement