-- Rick Buitenman <[email protected]> wrote
(on Friday, 08 May 2009, 09:15 AM +0200):
> On May 8, 2009, at 8:07 AM, keith Pope wrote:
> > 2009/5/8 Rick Buitenman <[email protected]> :
> > > There are a number of threads on bootstrapping modules, but I
> > > think it might help to isolate what seems to be a reoccuring
> > > source of confusion (at least it is for me):
> > >
> > > Am I right in assuming that *all* bootstraps of all modules are
> > > executed regardless for which module the request is?
> >
> > Yes, the module bootstrap resource will loop and call each module
> > bootstrap, though it skips the default module.
>
> Doesn't that partly negate a lot of the potential usefullness of the
> Zend_Application concept when used in a modular setup?
>
> I mean, I can understand why (I assume because routing hasn't happend
> yet, and there's no way to tell yet which module is actually being
> requested), and it's useful for those modules that add something that is
> used throughout the entire application.
>
> But the real world issue I have (and I assume from some of the questions
> here I'm not the only one) is that I want to initialize module-specific
> stuff only when that particular module is requested.
>
> Which is something I currently do via a Controller plugin, not a
> solution I'm particularly happy with. Although Zend_Application does
> inspire a more elegant, reusable way of implementing this, it would be
> great to have a similar "standard" solution, a sort of second phase
> bootstrap.
>
> Or am I completely missing the point of Zend_Application and is there
> already a better way of doing this?
You already identified the way to do this: controller plugins.
Bootstrapping is for stuff that needs to happen *on every request*.
Plugins give you the ability to determine if the given request requires
additional initialization.
One technique you can use is to instantiate a controller plugin,
register your module's bootstrap with it, and then register it with the
front controller:
class Foo_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initFooPlugin()
{
$bootstrap = $this->getApplication();
if (!$bootstrap instanceof Zend_Application) {
$bootstrap = $this;
}
$bootstrap->bootstrap('FrontController');
$front = $bootstrap->getResource('FrontController');
$plugin = new Foo_Plugin_FooInit($this);
$front->registerPlugin($plugin);
return $plugin;
}
}
Then, in your plugin, you can selectively call methods on the bootstrap
if the request matches that module.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/