duan00529 2010-06-23 08:03 采纳率: 100%
浏览 52
已采纳

Zend Framework:从另一个目录加载模块

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!

  • 写回答

2条回答 默认 最新

  • douhuanchi6586 2010-06-23 08:08
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能