dragon012100 2010-12-02 19:05
浏览 64
已采纳

如何让Zend Framework使用“特定于模块”的配置?

Reading the section Zend_Application_Resource_Modules in the docs here: http://framework.zend.com/manual/1.10/en/zend.application.available-resources.html

I noticed this:

You can specify module-specific configuration using the module name as a prefix or sub-section in your configuration file.

using this:

  [production]
  news.resources.db.adapter = "pdo_mysql"
  news.resources.db.params.host = "localhost"
  news.resources.db.params.username = "webuser"
  news.resources.db.params.password = "XXXXXXX"
  news.resources.db.params.dbname = "news"

To me this is a good idea. But, when I simply add these prefixes to certain things I want to be specific to my modules, nothing changes.

So my question is: How do I tell Zend Framework to actually use these module specific prefixes?

  • 写回答

1条回答 默认 最新

  • dongtiao2066 2010-12-02 20:50
    关注

    I use the following implementation of modules in Zend. It allows you to use "module-specific" configuration.

    application/config/config.ini
    -----------------------------
    [production]
    resources.modules[] =
    

    By doing this, you're telling Zend_Application that you want to use the Modules Bootstrap Resource plugin. The Modules plugin will load a separate bootsrap class for each of your modules, excluding the default module. Therefore, you need to create a new bootstrap class for your second module.

    application/modules/news/Bootstrap.php
    -----------------------------
    class News_Bootstrap extends Zend_Application_Module_Bootstrap {
    
       //---------------------------------------
       // Automatically load our resources
       //
       // NOTE: You don't have to add this, its
       //       just and example to show that you
       //       can customize the bootstrap
       //       process just for this module.
       public function _initModuleResourceAutoloader(){
    
          $this->getResourceLoader()->addResourceTypes(array(
             'modelResource' => array(
                'path' => 'models/resources',
                'namespace' => 'Resource'
             )
          ));
       }
    }
    

    This "News_Bootstrap" class will now be loaded and executed during the bootstrap process.

    The naming convention for this file is important as the Modules Resource plugin needs to be able to find the class. Note that you must name the file Bootstrap.php.

    Finally, you'll notice that you're subclassing the Zend_Application_Module_Bootstrap rather than Zend_Application_Bootstrap_Bootstrap like you do in the main bootstrap.

    Now, your module-specific configuration should work:

    [production]
    news.resources.db.adapter = "pdo_mysql"
    news.resources.db.params.host = "localhost"
    news.resources.db.params.username = "webuser"
    news.resources.db.params.password = "XXXXXXX"
    news.resources.db.params.dbname = "news"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)