Interesting approach, Robert.

Where DO you call the dbAdapter service, then? If I'm following, you'll need to 
call it at least once in your controller
or models wherein you need db access.

For what it's worth, I added the following to 
Application\Module\Module->onBootstrap():

        // set static database adapter
        $sm = $e->getApplication()->getServiceManager();
        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        Feature\GlobalAdapterFeature::setStaticAdapter($dbAdapter);

Seems to work like a champ. The only warning in the docs, from what I could 
find, is that onBootstrap() is called for
every request, so if I don't need to hit the database, the adapter is still 
created. As you said, I can live with this,
especially since very few pages will NOT need the db.

BTW, your code also helped me connect some now-really-obvious dots. Namely, the 
factories array returned in
Module->getServiceConfig() can be placed in module.config.php with the 
'service_manager' key. I don't know if it's
necessarily any better or worse to do so, but it's useful to know.

-Brad

On 3/15/2013 11:33 AM, Robert Basic wrote:

> I've done it like this 
> https://github.com/robertbasic/perfi/blob/master/config/autoload/global.php
> 
> now, the only problem I see with this is if I never call the dbAdapter 
> service from the SM in the request, but I do need
> the static adapter, it won't be set, because the dbAdapter factory was never 
> called. But I still have to come to a
> situation like this, so i can live with this.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to