I am looking to register a reference to the main Database Adapter in the Registry during Bootstrapping so it can be used elsewhere in my site (specifically the Authorisation action).
I have implemented an ugly fix where i create a Database Table object and call the getAdapter() method on it and pass through that. However, this is a bad way of doing it and I would like it to be available via the registry.
Does anyone know how to do this? Any help or pointers in the right direction are appreciated!
Cheers Stuart
Ps. Im using Zend Framework 1.8.
My 2 cents...
How to grab the default DB Adapter:
From Bootstrap:
From a Controller there are two methods:
Here is what i do:
Inside the bootstrap:
Inside the Initializer:
And finaly my config file looks like this:
Take a look at:
I didn't want to use the registry to store an object that I should be able to access, so I did a little digging. It turns out that the bootstrap is registered as the front controller parameter "bootstrap", which is accessible from any of your controllers as explained in this manual page for Zend_Application.
So in your controller classes you can get the db adapter that has been defined in your ini file like this: