2010年12月13日星期一

Re: [fw-mvc] Simple way of reusing database configuration settings in Zend_Config

To the best of my knowledge, this is not supported directly inside the
ini format or the default ini Config handler. If you wanted to code for
it, you could utilize the $config->merge() to merge config objects together.

http://framework.zend.com/apidoc/core/Zend_Config/Zend_Config.html#merge

This would then mean you are handling this special case with code somewhere.

If its just for brevity, I'd say not worry with it and leave it as is.
If it really becomes cumbersome (as in if there are more than 3), I'd
perhaps move them to a db.ini file and then beyond that, utilize this
merging option I mentioned above.

-ralph

On 12/12/10 12:00 AM, Nathan Garlington wrote:
> I have a number of databases. Rather than keep all of my site data all
> in one database, I have the data semantically sectioned into separate
> databases (using postgresql-9.1), i.e. blog, ecommerce, etc. While
> this helps me keep all of my data organized, it's a hassle when it
> comes to configuring database adapters. Here is what my
> application.ini looks like:
>
> ; Pgsql 'trailers' database Resource Config
> resources.trailersDb.adapter = "pdo_pgsql"
> resources.trailersDb.params.username = "my_username"
> resources.trailersDb.params.host = "localhost"
> resources.trailersDb.params.password = "my_super_secrete_password"
> resources.trailersDb.params.dbname = "trailers"
>
> ; Pgsql 'ecommerce' database Resource Config
> resources.ecommerceDb.adapter = "pdo_pgsql"
> resources.ecommerceDb.params.username = "my_username"
> resources.ecommerceDb.params.host = "localhost"
> resources.ecommerceDb.params.password = "my_super_secrete_password"
> resources.ecommerceDb.params.dbname = "ecommerce"
>
> ; Pgsql 'blog' database Resource Config
> resources.ecommerceDb.adapter = "pdo_pgsql"
> resources.ecommerceDb.params.username = "my_username"
> resources.ecommerceDb.params.host = "localhost"
> resources.ecommerceDb.params.password = "my_super_secrete_password"
> resources.ecommerceDb.params.dbname = "blog"
>
> ...etc.
>
> As you can see, all of the adapter config params are the same EXCEPT
> the database names. Is there a simple way to reuse config values and
> just substitute the one I need to change? For example, I know this can
> be done based on the APPLICATION_ENV variable [testing : production],
> but what about in the example above? Or is my way of organizing
> databases to unwieldy? What do the pros say?
>
> --regards,
> nathan
>
>

没有评论: