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条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值