2

应用程序.ini

resources.multidb.db1.adapter = "pdo_mysql"
resources.multidb.db1.host = "localhost"
resources.multidb.db1.username = "root"
resources.multidb.db1.password = "root"
resources.multidb.db1.charset = "utf8"
resources.multidb.db1.dbname = "admin"

resources.multidb.db2.adapter = "pdo_mysql"
resources.multidb.db2.host = "localhost"
resources.multidb.db2.username = "root"
resources.multidb.db2.password = "root"
resources.multidb.db2.dbname = "hp"
resources.multidb.db2.charset = "utf8"
resources.multidb.db2.default = true

引导程序.php:

        protected function _initDb(){           
            $resources = $this->getPluginResources('multidb');          
            Zend_Registry::set('db1', $resource->getDb('db1'));
            Zend_Registry::set('db2', $resource->getDb('db2'));
        }

类方法:

Array
(
    [0] => _initDb
    [1] => _initPrefix
    [2] => _initSession
    [3] => _initRouters
    [4] => _initAutoloader
    [5] => _initControllerHelper
    [6] => __construct
    [7] => run
    [8] => setResourceLoader
    [9] => getResourceLoader
    [10] => getAppNamespace
    [11] => setAppNamespace
    [12] => setOptions
    [13] => getOptions
    [14] => hasOption
    [15] => getOption
    [16] => mergeOptions
    [17] => getClassResources
    [18] => getClassResourceNames
    [19] => registerPluginResource
    [20] => unregisterPluginResource
    [21] => hasPluginResource
    [22] => getPluginResource
    [23] => getPluginResources
    [24] => getPluginResourceNames
    [25] => setPluginLoader
    [26] => getPluginLoader
    [27] => setApplication
    [28] => getApplication
    [29] => getEnvironment
    [30] => setContainer
    [31] => getContainer
    [32] => hasResource
    [33] => getResource
    [34] => __get
    [35] => __isset
    [36] => bootstrap
    [37] => __call
    [38] => _bootstrap
    [39] => _executeResource
    [40] => _loadPluginResource
    [41] => _markRun
    [42] => _resolvePluginResourceName
)

当我运行应用程序时,它的返回错误:调用非对象上的成员函数 getDb()

谁能帮我?

谢谢!

对不起,我的英语不好。

4

1 回答 1

2

你的函数中有错字 -

protected function _initDb(){           
$resources = $this->getPluginResources('multidb');
// changed $resource to $resources
Zend_Registry::set('db1', $resources->getDb('db1'));
Zend_Registry::set('db2', $resources->getDb('db2'));
}
于 2013-04-11T06:40:26.537 回答