I usually access the database through my table objects.
However, recently I've needed to do things directly with the database
object. I found the simplest choice was $GLOBALS['db'] = $db.
It's so rare that I directly use it, and a global lookup is pretty cheap
(right?). Anytime I need an object instantiated in my bootstrap I'll
assign it to a global. If I access it more than once in a function, I'll
either localize the variable or try and get it a more reliable way.
I didn't think about using:
Zend_Db_Table_Abstract::getDefaultAdapter();
That seems like it might be a good alternative choice.
Kevin Hallmark
PHP Developer
Bonnier Corporation
-----Original Message-----
From: Jim Scherer [mailto:
jscherer26@...]
Sent: Thursday, May 15, 2008 10:12 AM
To:
fw-general@...
Subject: Re: [fw-general] Dumb Question
if you are using Zend_Controller_Front as I am you can set it as a
parameter:
$frontController = Zend_Controller_Front::getInstance();
$frontController->setParam('db', $db)
and then in your controller:
$this->getFrontController()->getParam('db')
So many ways to skin a cat.
Jim
Joseph Crawford wrote:
>
> In my index.php bootstrap file I setup the database connection into a
> variable $db. Now I need to access this in other controllers. This
> seems like a dumb question to me but do I need to global $db; before I
> can access it in the indexAction method of the controller or is it in
> the global scope by default?
>
> Thanks,
> Joseph Crawford
>
>
--
View this message in context:
http://www.nabble.com/Dumb-Question-tp17253025p17254165.htmlSent from the Zend Framework mailing list archive at Nabble.com.