Zend Framework:从另一个目录加载模块
大家好,这是我在 Stack Overflow 上的第一个问题。我认为这个网站对我帮助很大,所以我也尝试一下。
我目前正在开发多个需要从公共模块目录继承模块的 Zend Framework 应用程序。使用的文件结构是传统方法(省略实际名称和引用以保护应用程序结构):
/application1
/application
/modules
/module1
/module2
/module3
/...
/application2
/application
现在我已经尝试手动自动加载 Application2 引导程序中的每个模块,如下所示:
$moduleLoader = new Zend_Application_Module_Autoloader(
array('namespace' => 'Prefix', 'basePath' => path_to_application1_application_modules_modulename)
);
$autoloader->pushAutoloader($moduleLoader);
这可行,但正如您可以想象的那样,这变得相当困难一项乏味的工作。现在我还尝试在 FrontController 中设置公共模块目录,如下所示:
$frontController = Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory(path_to_application1_application_modules);
但这似乎不会引导任何模块。我是不是忘记了什么重要的事情?非常感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 config.ini 路径中使用配置
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
,然后只需使用自动加载器。它对我有用,我只是通过更改 config.ini 中的
resources.frontController.moduleDirectory
路径来使用另一个应用程序中的模块。要在您的配置中尝试它,请在 application2 config.ini 中放置
resources.frontController.moduleDirectory = APPLICATION_PATH "/../application1/application/modules"
LE:
如果您希望模块引导,请在 moduleDirectory 行之后添加 config.ini
resources.modules[] = ""
。我自己尝试过,如果没有这个,进入随机模块时其他模块不会被引导。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.当引导模块时,您将其作为 Zend_Application_Module_Bootstrap 进行。这是显而易见的,但该文件也应该位于根模块文件夹中。
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.