views:

69

answers:

2

Hey there guys, this is my first question on Stack Overflow. I figured this website has helped me alot so I give it a shot as well.

I'm currently working on multiple Zend Framework applications that need to inherit modules from a common module directory. The file structure used is the conventional method (omitting actual names and references to protect application structure):

/application1
    /application
        /modules
            /module1
            /module2
            /module3
            /...

/application2
    /application

For now i've tried manually autoloading every single module in the bootstrap of Application2 like so:

$moduleLoader = new Zend_Application_Module_Autoloader(
    array('namespace' => 'Prefix', 'basePath' => path_to_application1_application_modules_modulename)
);
$autoloader->pushAutoloader($moduleLoader);

This works, but as you can imagine this becomes quite a tedious work. Now I've also tried setting the common module directory in the FrontController like so:

$frontController = Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory(path_to_application1_application_modules);

But this doesn't seem to Bootstrap any of the modules. Am I forgetting about something important? Your help is much appreciated!

A: 

You can use the config resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" in your config.ini path and then just use the autoloader.

It works for me, I just used modules from another application by changing the path for resources.frontController.moduleDirectory in config.ini.

To try it on your configuration, in application2 config.ini you should put resources.frontController.moduleDirectory = APPLICATION_PATH "/../application1/application/modules"

LE: If you want you modules bootstrapped add in config.ini resources.modules[] = "" after the line with moduleDirectory. Tried it myself and without this, other modules are not bootstrapped when entering a random module.

Bogdan Constantinescu
In anyway I try it still doesn't bootstrap my modules. When I debug to see weither the module bootstraps are called, they don't show up. I'm still clueless...
Berry Ligtermoet
Add the line above after the `later edit` :)
Bogdan Constantinescu
Hm none of it seems to have effect. You mentioned "then just use the autoloader." How would you suggest I use it? By creating a new module autoloader object and add it to the autoloader? So basicly as I described in the question.
Berry Ligtermoet
Oh I have some results now. I get output from the modules now! Now there's only the problem that models don't seem to be loaded. I guess there's no other way to do this then to use the Module Autoloader object?
Berry Ligtermoet
Also it still seems bootstraps aren't dispatched. They aren't even loaded. I put in a parse error on purpose but it doesn't fall over it. I do on the other hand get output from my test controller. This is getting weird
Berry Ligtermoet
Now you have to put `Zend_Autoloader` at work to register the namespace for that application (considering your models have their classes named after the Zend convention; eg: Module_Model_Something)
Bogdan Constantinescu
Yes they have, but I've arranged autoloading of the module in the bootstrap of the module itself. This decision is based on that the init methods in the module bootstrap get executed. If the bootstrap isn't dispatched, the module won't be autoloaded. Or would this be a design flaw?
Berry Ligtermoet
Some extra info. From outputting the result of get_inluded_files() I can see non of the Bootstraps from the modules are included. I have added resources.modules[] = "" as I've been using this from the beginning.
Berry Ligtermoet
A: 

When bootstrapping your modules are you doing it as a Zend_Application_Module_Bootstrap. It's obvious but the file should also be in the root module folder.

Ashley