News Feed
Sections




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

Master Zend Framework:
Howto Use Constructor Injection In ZF2
April 15, 2014 @ 12:50:33

The Master Zend Framework site has a new tutorial posted today introducing you to constructor injection in Zend Framework 2 applications, specifically in controller classes.

s it right to use setter injection? Or is it evil, to be avoided at all costs, for the explicitness of constructor injection? In today's post, we explore that and how to implement constructor injection in ZF2 controller classes. Recently on Master Zend Framework, I wrote about using Setter Injection in Zend Framework 2, to supply dependencies to Controller classes.

He talks about the "magic" that can come with frameworks and how constructor injection of the ServiceManager can help clarify and remove some of the problems associated with "magic". He walks you through three steps to getting the ServiceManager injected into the classes:

  • Implement a Class Constructor
  • Initialise your controllers via FactoryInterface
  • Use factories Instead of invokables

He also points out a few benefits to this method of injection, including that it makes the controllers easier to test and the main goal - lack of "magic" in dependencies.

0 comments voice your opinion now!
constructor injection zendframework2 tutorial servicemanager

Link: http://www.masterzendframework.com/tutorial/howto-constructor-injection-in-zf2

blog comments powered by Disqus

Similar Posts

Jason Grimes' Blog: Using Doctrine 2 in Zend Framework 2

Rob Allen's Blog: Quiet around here (Tutorial Translation - Brazillian Portuguese)

IBM developerWorks: What's new in PHP V5.2, Part 4: Using the new ZIP extension

ZendCasts.com: Creating RSS & Atom Feeds with Zend_Feed

Extending Twig Templates: Inheritance, Filters, and Functions


Community Events





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


refactor laravel code api introduction developer threedevsandamaybe release podcast symfony2 interview language community list unittest series install testing opinion framework

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