Registering Zend Database Adapter in Registry

后端 未结 9 2011
温柔的废话
温柔的废话 2020-12-23 00:07

I am looking to register a reference to the main Database Adapter in the Registry during Bootstrapping so it can be used elsewhere in my site (specifically the Authorisation

9条回答
  •  误落风尘
    2020-12-23 00:20

    Thanks for the replies. Ive decided to change the accepted answer and post the solution I finally used - which is insanely simple in the end!!

    This is basically based on Dcaunt's comment...

    In the bootstrap class..

    protected function _initDb()
    {
        $resource = $bootstrap->getPluginResource('db');
    
        $db = $resource->getDbAdapter();
    
        Zend_Registry::set("db", $db);
    }
    

    Then access that elsewhere with...

    $dbAdapter = Zend_Registry::get("db");
    

    Thanks for the help and hopefully this helps someone else.

提交回复
热议问题