假設你的數據庫適配器安裝在你的application.ini類似於:
resources.db.adapter = "pdo_Mysql"
resources.db.params.username = "music"
resources.db.params.password = "music"
resources.db.params.dbname = "music"
resources.db.isDefaultTableAdapter = true // add this line to make this adapter default, important if using more then one adapter.
在bootstrap.php中你可以創建類似的新方法:
protected function _initDbAdapter() {//can be named anything as long as it starts with _init
$db = new Zend_Config($this->getOptions('db'));//get all db adapter resources
Zend_Registry::set('DbAdapter', $db); //save to Zend_registry key DbAdapter
}
ByteNudger是正確的如何使用註冊表:
$authAdapter = new Acai_Auth_Adapter_DbTable($dbAdpater);
但是有一種方法可以避免所有這種引導企業湖。如果您只使用一個數據庫適配器,請嘗試:
//This will pass in the currently default adapter, if you only have one adapter...
$authAdapter = new Acai_Auth_Adapter_DbTable(Zend_Db::getDefaultAdapter);
希望這會有所幫助。
很好,謝謝! – Ayrx 2012-07-15 12:39:59