Rob Allen has a quick new post to his site showing you how to inject dependencies into controllers in a Zend Framework v2 based application.
When starting working with Zend Framework 2, it’s common to copy the skeleton and put your controller definitions in module.config.php. The controllers keyword is picked up by the ControllerManager which is an instance of the ServiceManager which means that it creates the controller instance for you when the dispatcher needs it. As it’s just a service manager, we configure it to inject the dependencies that the controller needs rather than having to go fishing for them later.
He shows how to write a "getControllerConfig" method to populate two items into the factory call for a "Blog" controller, blog mapper and content mapper classes. He also includes a reminder that ZF2 controllers have no constructor, so dependencies can be more easily injected and used directly in the class.