News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Injecting dependencies into your ZF2 controllers
April 23, 2014 @ 09:06:27

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.

0 comments voice your opinion now!
dependency injection controller zendframework2 tutorial factory

Link: http://akrabat.com/zend-framework-2/injecting-dependencies-into-your-zf2-controllers/

blog comments powered by Disqus

Similar Posts

Daniel Cousineau: Using Symfony Console From Scratch

PHPMac.com: Building and Installing Apache 2.2.2 and PHP 5.1.3 (or 5.1.4) on Mac OS X 10.4.6

Joey Rivera's Blog: Using Zend_Paginator with Twitter API and Zend_Cache

Lorna Mitchell's Blog: Building A RESTful PHP Server: Routing the Request

IBM developerWorks: Squash bugs in PHP applications with Zend Debugger


Community Events





Don't see your event here?
Let us know!


introduction configure threedevsandamaybe install series interview podcast api list language library release code symfony community unittest wordpress developer application laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework