2

My structure is as follows:

/modules
 /module1
 /module2
 /module3

For example; Site A would use module1 and module3 but Site B would require all 3 modules. I know this data during inital bootstrap so it would seem a waste for Site A to boostrap module2. Is there a way I can tell Zend to boostrap only certain modules?

I'm currently adding all like this:

    $front = Zend_Controller_Front::getInstance();
    $front->addModuleDirectory(MODULE_PATH);

3 Answers 3

1

Since you implied you know which modules are required for each site, let's say you had these in an array $modules. It's then as simple as doing this in your bootstrap:

$front = Zend_Controller_Front::getInstance();
foreach ($modules as $module) {
    $front->addControllerDirectory(APPLICATION_PATH."/modules/$module/controllers", $module);
}
Sign up to request clarification or add additional context in comments.

Comments

1

No. You can't. Well, you can - add only the module you need - i.e.: make a pre-router ;)

But from the idea of modules it doesn't make sense to run only some bootstraps. You need the bootstrap to run, so that the routes from the module are added ... for example ;)

Comments

1

It is my understanding that even if you have specific bootstraps for each module, every bootstrap including the modules that you are not using will fire. This is because bootstraps are a "preparing" class. What you can do is create plugins, and test for what module is being used.

http://weierophinney.net/matthew/archives/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html

Matthew Weier O'Phinney explains why it is done this way.

I would minimize the amount of bootstraping in modules, and provide plugins for any code that can be outsourced.

For instance, I wanted to have a certain module disable layouts upon execution, so instead of doing this in its boostrap, I created a plugin, and just test for if the module is being used.

class Custom_Module_Plugin_DisableLoadLayout extends Zend_Controller_Plugin_Abstract {
    /*
     * @param Zend_Controller_Request_Abstract $request
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
            $module = $request->getModuleName();
            $layout = Zend_Layout::getMvcInstance();

            if($module == 'load'){
                $layout->disableLayout();
            }
}
}

If your familiar with plugins you know that plugins fire upon every load via frontcontroller, so you could basically have one plugin, and test for the module name, and act accordingly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.