Zend 模块特定配置的问题 [英] problem with zend module specific configuration

查看:27
本文介绍了Zend 模块特定配置的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 zend 框架构建 REST Web 服务,我使用模块来分隔我的 api 版本.

iam using zend framework to build a REST web service and i am using modules to separate my api versions.

现在,我想为我的每个模块(v1 和 v2)都有一个单独的配置文件,主要用于指定单独的数据库连接.

Now, i want to have a separate configuration file for each of my module (v1 and v2), mainly for specifying separate database connections.

我有一个这样的目录结构:

I had a directory structure like this:

- application
      - modules
            - v1
                  - controllers
                  - models
                  - views
                  - configs
                    - module.ini         
            - v2
                  - controllers
                  - models
                  - views  
                  - configs
                    - module.ini
      - configs
            - application.xml   
- library

我已经在 application/configs 中的application.ini"中提到了数据库连接.我阅读了here 关于模块特定的配置并尝试它.

I already have the database connection mentioned in my "application.ini" inside application/configs. I read here about module specific confurations and tried it.

我从 application.ini 中删除了这些数据库参数并将其放在 module.ini 中:

I removed these database params from application.ini and put it in module.ini:

[production]
resources.db.adapter = PDO_MYSQL
resources.db.params.host = 127.0.0.1
resources.db.params.username = myuser   
resources.db.params.password = mypwd
resources.db.params.dbname = my_db
resources.db.params.profiler.enabled = "true"
resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug"

.....

但是当我访问模块控制器中的数据库时,我收到一条错误消息,提示未找到适配器...".请帮忙...

But i got an error saying "No adapter found..." when i accessed database in my module's controller. Please help...

推荐答案

您在问题中引用的解决方案 (My_App) 不需要针对特定​​于模块的数据库连接进行任何额外配置,或任何其他特定于模块的配置(路由除外)).您需要做的就是在 application.ini 中将 MultiDb 资源声明为 db1.然后,您可以在请求的模块的相应 module.ini 中将任何特定于模块的数据库资源声明为 db2、db3、db4...等......您不需要任何额外的配置.我在我的 github 上的下载文件中放置了一个示例.不要不尊重上面mingos"的回应,但在 My_App 中不需要任何额外的代码.

The solution (My_App) you refer to in your question does not require any additional configuration for module specific database connections, or any other module specific configuration (except for routes). All you need to do is to declare a MultiDb resource in the application.ini as db1. Then you can declare any module specific database resource in the requested module's respective module.ini as db2, db3, db4... etc... you do not need any additional configuration. I placed an example in the download file at my github. Not to disrespect the response by "mingos" above but there's no need for any additional code in My_App.

以下是从下载 (application.ini) 中提取的准确文字:

Here's the exact verbage taken from the download (application.ini):

...if this resource is declared here, then it
will be available to all modules. If different
db resources need to be used for different
modules then MultiDB resource can be
initiated. Example: A general db resource can be
defined here and a module specific db can be
declared in its corresponding module.ini.
The db resource declared in the module will not
be available to other modules but the db resource
in this application.ini will be available to all
modules...

然后它在下载中声明一个单独的数据库资源作为示例.只需将其更改为多数据库资源即可.在 application.ini 中声明应用程序范围所需的 db 资源,并在其各自的 module.ini 文件中声明任何特定模块所需的任何其他 db 资源.这很简单.这就是你需要做的.一旦你理解了 My_App 背后的逻辑,你就会发现它非常强大.

Then it declares a single db resource as an example in the download. Just change it to a multi db resource. Declare the application wide needed db resource in application.ini, and any additional db resource that is needed for any specific module in their respective module.ini files. It's straightforward. That's all you need to do. Once you understand the logic behind My_App, you will see it's very powerful.

这篇关于Zend 模块特定配置的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆