Zend公司:从引导访问模式会引发异常

Zend公司:从引导访问模式会引发异常

问题描述:

这是我在引导代码:Zend公司:从引导访问模式会引发异常

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适配器在执行Bootstrap时尚未初始化(奇怪?)。我应该如何使代码在Bootstrap中工作?是否有必要使用Zend_Db_Table :: setDefaultAdapter()创建和设置适配器?

我在问,因为如果代码不在Bootstrap中,它需要在两个不同的地方复制,它也看起来像它属于Bootstrap。

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

请尝试更改您的引导方法,如下所示,以便明确引导数据库资源。

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()); 
} 
+2

+1!更多信息在这里 - [Zend的应用 - 操作理论 - 依赖追踪](http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of- operation.bootstrap.dependency-tracking) – Phil 2012-02-09 00:10:50

+0

谢谢,它的工作原理。 – clime 2012-02-09 01:20:49