Exception Zend:从引导访问模型会引发异常

Exception Zend:从引导访问模型会引发异常,exception,zend-framework,model,bootstrapping,Exception,Zend Framework,Model,Bootstrapping,这是我在Bootstrap中的代码: public function _initRegistry() { $systemConfigModel = new Application_Model_DbTable_SystemConfig(); Zend_Registry::set('config', $systemConfigModel->getSystemConfig()); } 这是我得到的一个例外: ( ! ) Fatal error: Uncaught excepti

这是我在Bootstrap中的代码:

public function _initRegistry()
{
    $systemConfigModel = new Application_Model_DbTable_SystemConfig();
    Zend_Registry::set('config', $systemConfigModel->getSystemConfig());
}
这是我得到的一个例外:

( ! ) Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Application_Model_DbTable_SystemConfig' in /usr/share/php5/Zend/Db/Table/Abstract.php on line 755
( ! ) Zend_Db_Table_Exception: No adapter found for Application_Model_DbTable_SystemConfig in /usr/share/php5/Zend/Db/Table/Abstract.php on line 755
如果我在
BaseController
中调用它,它就可以正常工作。看起来我在
application.ini
中指定的PDO适配器在执行引导时还没有初始化(奇怪?)。我应该怎么做才能使代码在引导中工作?是否需要使用Zend_Db_Table::setDefaultAdapter();创建和设置适配器


我这样问是因为如果代码不在引导中,它需要在两个不同的地方复制,而且看起来它也属于引导。

您是正确的,在引导过程中,您数据库的Zend应用程序资源尚未初始化

尝试如下更改引导方法,以便显式引导db资源

public function _initRegistry()
{
    $this->bootstrap('db'); // Bootstrap the db resource from configuration

    $db = $this->getResource('db'); // get the db object here, if necessary

    // now that you have initialized the db resource, you can use your dbtable object
    $systemConfigModel = new Application_Model_DbTable_SystemConfig();
    Zend_Registry::set('config', $systemConfigModel->getSystemConfig());
}
+1! 更多信息请点击此处-