Zend Framework with ZFDebug, how to get the db adapter
I have the follow开发者_如何学Going in my application.ini file
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = ".."
resources.db.params.password = ".."
resources.db.params.dbname = "lsc3_base"
resources.db.isDefaultTableAdapter = true
Now this works perfectly and I can query the database no problem.
Im trying to install ZFDebug which also was easy using the following in my main bootstrap.php file
` protected function _initZFDebug() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('ZFDebug');
$options = array(
'plugins' => array('Variables',
'Time',
#'Auth',
'Memory',
'Registry',
'Database' => array('adapter' => $db),
'File' => array('basePath' => '/path/to/project'),
#'Cache' => array('backend' => $cache->getBackend()),
'Exception')
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
` Now this obviously gives me a notice saying $db undefined.
Question is how do I get hold of $db?
I have tried the following: $db = Zend_Db_Table::getDefaultAdapter(); $db = $this->getPluginResource('db');
Which I am assuming dont work because its connecting to the database AFTER doing all of the things in my bootstrap. How can I resolve this?
This should help, make a $db variable like this:
$this->bootstrap('db');
$db = $this->getPluginResource('db')->getDbAdapter();
精彩评论