简体   繁体   中英

Zend Framework: Loading modules from another directory

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM