Hi, iam using zend framework to build a REST web service and i am using modules to separate my api versions.
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
I already have the database connection mentioned in my "application.ini" inside application/configs. I read here about module specific confurations and tried it.
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...
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.
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...
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.