I think this is because your controller does not implement the ServiceLocatorAwareInterface interface. You can see the Zend \ ServiceManager \ AbstractPluginManager class in the build method:
public function __construct(ConfigInterface $configuration = null) { parent::__construct($configuration); $self = $this; $this->addInitializer(function ($instance) use ($self) { if ($instance instanceof ServiceLocatorAwareInterface) { $instance->setServiceLocator($self); } }); }
therefore, you must implement it if you want to use the ServiceLocator, or extend the Zend \ Mvc \ Controller \ AbstractActionController class that it implemented in ServiceLocatorAwareInterface.
source share