News Archive
PhpRiot Newsletter
Your Email Address:

More information

ZF2's New Controller::init()

Note: This article was originally published at phly, boy, phly on 31 July 2012.

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.

class MyController extends Zend_Controller_Action { public function init() { // do some stuff! } }

But this feature is missing from ZF2; how can we accomplish this sort of pattern?