How to execute module bootstrap resources present inside another module's bootstrap in Zend Framework 1?

StackOverflow https://stackoverflow.com/questions/15890985

Question

I am bootstrapping my application with Zend_Application_Module_Bootstrap inside the various module directories. How can I require that a resource inside another module's bootstrap be executed first?

// app/modules/user/Bootstrap.php
class User_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initUser()
    {
    }
}

// app/modules/author/Bootstrap.php
class Author_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initAuthor()
    {
        $this->bootstrap('user'); // Fatal:  Resource matching 'user' not found
    }
}
Was it helpful?

Solution

I've decided to use plugins to achieve this fine-grained functionality, as execution order cannot be managed properly, therefore making module bootstraps a poor choice to place code with dependencies.

Used referenced answer below to base my decision:

load /execute module based bootstraps from each module in certain order

OTHER TIPS

According to this thread from the ZF1 mailing list, you can access the module-bootstraps via the modules resource of the application bootstrap.

Man, what a mouthful. Here's what I mean:

// app/modules/user/Bootstrap.php
class User_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initUser()
    {
    }
}

// app/modules/author/Bootstrap.php
class Author_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initAuthor()
    {
        $app = $this->getApplication(); // it's actually the application *bootstrap*
        $app->bootstrap('modules');
        $modulesResource = $app->getResource('modules'); 
        $userBootstrap = $modulesResource->user;
        $userBootstrap->bootstrap('user'); // should be cool
    }
}

In my own experience, as soon as one of my module-level resources needs to be referenced in more than one module - especially during bootstrapping - I just push the bootstrapping of that resource up into the application-level bootstrap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top