Actually it's even simpler than that.
Assuming you're using Zend_Application along with the application.ini you
provided all you need to do in your controllers is
// Get the database adapter
$bootstrap = $this->getInvokeArg('bootstrap');
$db = $bootstrap->getResource('db');
You don't need the extra bootstrap code since it will already be available
as the "db" resource
>From there you could inject it into your models on instantiation.
Martin Carpentier
On Wed, Sep 16, 2009 at 14:50, <[email protected]> wrote:
> Hello Bence,
> you can call it in any controller:
>
> $bootstrap = $this->getInvokeArg ( 'bootstrap' );
> $db = $bootstrap->getResource ( 'dbconn' );
>
> wher:
> Bootstrap.php
> has this method:
>
> protected function _initDbconn(){
> $resource = $this->getPluginResource('db');
> $db = $resource->getDbAdapter();
> return $db;
> }
>
> application.ini
> resources.db.adapter = "pdo_mysql"
> resources.db.params.host = "localhost"
> resources.db.params.username = "whatever"
> resources.db.params.password = "whatever"
> resources.db.params.dbname = "whatever"
> resources.db.isDefaultTableAdapter = true
>
>
> rgds
> Armand
>
> On Wed, 16 Sep 2009 14:39:20 +0200, BB <[email protected]> wrote:
> > Hello,
> >
> > how can I get the database adapter instance in the model (or anywhere
> > else) without the Zend_Db_Table's getDefaultAdapter()?
> >
> > Foo.php:
> > class Model_Foo
> > {
> > protected $_db;
> > public function __construct()
> > {
> > $this->_db = ???;
> > }
> > }
> >
> > in the application.ini I have the following lines:
> > resources.db.adapter = "mysqli"
> > resources.db.params.host = "localhost"
> > resources.db.params.username = "foo"
> > resources.db.params.password = "bar"
> > resources.db.params.dbname = "baz"
>