News Feed
Sections




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

Matthew Weier O'Phinney:
ZF2's New Controllerinit()
July 31, 2012 @ 08:44:36

In his latest post Matthew Weier O'Phinney introduces you to the new init() method in the Zend Framework 2 controllers and how it differs from the one in version 1.

In Zend Framework 1, controller's had an init() method, which was called after the controller was instantiated. The reason for it was to encourage developers not to override the constructor, and thus potentially break some of the functionality (as a number of objects were injected via the constructor). init() was useful for doing additional object initialization. [...] But this feature is missing from ZF2; how can we accomplish this sort of pattern?

In Zend Framework 2, there's no Controller constructor by default anymore, so you have to do things slightly differently. He shows you how to use the event manager to simulate the same thing, attaching an event to the "dispatch" of the controller to do the work. He came back and updated the post with a second method that could do the same thing - using the ServiceManager from inside a module and attaching the event that way.

0 comments voice your opinion now!
controller init method servicemanager event dispatch


blog comments powered by Disqus

Similar Posts

Alexander Netkachev's Blog: A little bit more about Zend_Controller plugins

Matthew Weir O'Phinney's Blog: Extending Singletons

Avnet Labs Blog: TDD with Zend Framework - testing controllers

DevShed: Positioning Strings with the show_xy() Method in PDF Documents with PHP 5

Tim Koschuetzki's Blog: Composing Methods: Substitute Algorithmn


Community Events

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


library interview php7 podcast laravel series install voicesoftheelephpant xdebug example framework introduction unittest language release community laravel5 extension api opinion

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