-- Nick Lo <[EMAIL PROTECTED]> wrote
(on Tuesday, 05 December 2006, 08:51 PM +1100):
> Hi Rob,
> 
> >Nowadays, you should override Zend_Controller_Action::init() rather  
> >than
> >override the constructor. Zend_Controller_Action::__construct() calls
> >init() as the last thing it does.
> 
> I like the way you say "nowadays" in an "well yes, that was how we  
> used to do it back in the day, but of course, the modern way is..."  
> kind of way ;-)
> 
> Yeah, as you'll have seen I did get to that further down that post
> 
> >Alternatively, you could override  
> >Zend_Controller_Action::preDispatch()
> >which gets called directly before each Action function.
> 
> That sounds like both init and preDispatch now have similar  
> roles ...what distinguishes the two?

init() happens at object instantiation, which happens before
preDispatch() -- it's basically provided so that you don't need to
override the constructor, and thus possibly forget to set the request,
response, and other parameters (as you discovered the hard way).

Theoretically, if something goes wrong during the initialization
sequence, you could throw an exception, in which case the preDispatch()
will not be called -- this may be handy so that you can, for instance,
setup your models, etc., and, if unavailable, prevent the action from
dispatching. preDispatch() might then actually use the models to do some
determination of whether or not to skip the current action.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to