2011-08-04 67 views
0

我創建了一個基本的zend framwework項目,並在那裏添加了一些額外的模塊。 在每個模塊上,我決定爲它創建單獨的配置文件。我跟着在網絡上的一些資源,因爲它表明,我把下面的代碼在其引導類(而不是應用程序引導類)問題設置模塊特定配置文件

class Custom_Bootstrap extends Zend_Application_Module_Bootstrap { 

    protected function _bootstrap() 
    { 
     $_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV); 
     $this->_options = array_merge($this->_options, $_conf->toArray()); 
     parent::_bootstrap(); 
    } 
} 

它甚至沒有工作,它給出了一個錯誤。

Strict Standards: Declaration of Custom_Bootstrap::_bootstrap() should be compatible with that of Zend_Application_Bootstrap_BootstrapAbstract::_bootstrap() in xxx\application\modules\custom\Bootstrap.php on line 2 

回答

0

綜觀Zend_Application_Bootstrap_BootstrapAbstract的源代碼,_bootstrap的聲明如下所示:

protected function _bootstrap($resource = null) 
    { 
     ... 
    } 

所以,你只需要改變你的覆蓋看起來像這樣:

protected function _bootstrap($resource = null) 
    { 
     $_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV); 
     $this->_options = array_merge($this->_options, $_conf->toArray()); 
     parent::_bootstrap($resource); 
    } 
+0

不,它沒有幫助,同樣的錯誤 – mrN

+0

所以,你現在有你的子類的方法定義爲'protected function _bootstrap($ resource = null)',你仍然得到錯誤?你使用什麼版本的ZF?你可以看看'Zend_Application_Module_Bootstrap'來看看'_bootstrap'是如何聲明的嗎? – ChrisA

+0

我使用的是最新版本,1.11.9 – mrN

2

不要覆蓋bootstrap方法,只需讓你的模塊配置一個資源:

class Custom_Bootstrap extends Zend_Application_Module_Bootstrap 
{ 
    protected function _initConfig() 
    { 
     $config = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV); 
     $this->_options = array_merge($this->_options, $config->toArray()); 

     return $this->_options; 
    } 
} 

這將在模塊自舉時自動運行。

+0

但我需要將新設置與新設置合併。 – mrN

+0

您仍然可以以同樣的方式執行此操作 - 我已將陣列合併添加到我的代碼示例中。 –

+0

你正在合併$ this - > _options,並返回$ config ...你確定它是正確的...等我先嚐試 – mrN