How do I get the Zend_Application's database into a model class?

Posted by Billy ONeal on Stack Overflow See other posts from Stack Overflow or by Billy ONeal
Published on 2010-04-13T02:13:37Z Indexed on 2010/04/13 2:23 UTC
Read the original article Hit count: 338

Filed under:
|
|

I have a Zend_Framework application, which has a whole bunch of model classes.

I need these model classes to be able to access the application's database (naturally).

Currently I've put this in my index.php:

Zend_Registry::set('db',
        $application->bootstrap()->getBootstrap()
        ->getPluginResource('db')->getDbAdapter());

And then $db = Zend_Registry::get('db'); in each of my model classes that require the database.

But this seems like a horrible horrible hack. Am I missing something basic here?

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about php