的application.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
bootstrap.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()。
任何人都可以帮助我吗?
谢谢!
抱歉我的英语不好。
答案 0 :(得分: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'));
}