protected function _initDatabase()
{
$params = array(
'host' => '',
'username' => '',
'password' => '',
'dbname' => '',
);
$database = Zend_Db::factory('PDO_MYSQL', $params);
$database->getConnection();
return $database;
}
.
class App_Controller_Plugin_Test extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Http $request)
{
// how i get database?
}
}
You can always get a reference to the front controller:
From that you can get the bootstrap:
From the bootstrap you can get bootstrap plugins:
But that’s a lot of extra plumbing!
Honestly, you’d be better off storing the database adapter object in the registry during your bootstrap:
Then you can get the database adapter anywhere:
See also my answer to What is the “right” Way to Provide a Zend Application With a Database Handler