On 8 Jan 2009, at 11:13, Ionut Gabriel Stan wrote:

On 1/8/2009 12:05, Rob Allen wrote:

On 8 Jan 2009, at 09:26, Bart McLeod wrote:

You can of course have a base custom controller, but you do not need to.

Depending on what you need exactly you can use either an action helper in the init method or a plugin or both a plugin and an action helper.

public function init(){
$this->_helper->myInit(); //instead of your six lines of code
}


Actually, if you have a My_Controller_Action::init(), you don't need to
define and init() at all in the child classes, whereas if you use a
helper, you do need to define the init() in the controllers where you
need the myInit().

Depends on the place where you register the helper, because HelperBroker::__construct() will call the init() method of all registered helpers at the time Zend_Controller_Action is instantiated. Then, the same HelperBroker will call the preDispatch() and postDispatch() method of all helpers before and, respectively, after Zend_Controller_Action::dispatch().

There's a nice representation of this process here:

http://surlandia.com/wp-content/uploads/2008/11/zf-dispatch-lifecycle-bw.jpg

So, IMHO, a helper could be the solution, the only issue remaining might be the place to register the helper and then what callback method to use, init() or preDispatch().



That's correct, but if you register the helper with the broker and use the hooks, you will get the initialisation for every single controller. If you use a superclass, then you can choose whether to extend a given controller with it or not.

Personally, I would use a helper and an init() function in the controllers where I want to use that common functionality.

Regards,

Rob...

Reply via email to