coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Setter for $_db var #54

Closed back-2-95 closed 12 years ago

back-2-95 commented 12 years ago

Hi,

Could there be public set method for defining protected static $_db ? Llike setDb($db) ?

I would like to store db name in my config and set it once for all my document types. And of course with this method I could use other dbs also.

br, Marko

coen-hyde commented 12 years ago

There is already a way to accomplish this, but it's not in the docs.

If you set an attribute called database in your config file, along where you usually specify host, username etc then that will be the database used so long as there is no static::$_db variable set on models.

I've been meaning to document this but I'm waiting until i finish a related feature.

back-2-95 commented 12 years ago

Can you provide quick example? I use application.ini file to set my Zend_Application.

coen-hyde commented 12 years ago

Checkout https://github.com/coen-hyde/Shanty-Mongo/wiki/Connections

You could have something like this in your .ini file:

mongo.host = 'mongohost.local' mongo.database = 'my_database'

Then do something like: Shanty_Mongo::addConnections($config->mongo)

Then remove the static::$_db setting in your models.

back-2-95 commented 12 years ago

Thanks! I appreciate this! =)