我的项目文件夹是 demo,里面有文件夹 application、library 和 public。在应用程序文件夹中,我有一个名为 configs 的文件夹,其中有一个文件“application.ini”,其中包含我的数据库参数。因此,在应用程序目录中的 bootstrap.php 中,我在 Zend 注册表中的一个名为的函数中设置了我的数据库_initDbAdapter
:
$config = new Zend_Config_Ini('/demo/application/configs/application.ini', 'development');
Zend_Registry::set('config', $config);
$db = Zend_Db::factory($config, $config->resources->db->params->asArray());
Zend_register('db', $db);
当我将浏览器指向 localhost/demo/public/ 时(因为我的 index.php 位于公共文件夹中),我收到以下错误:
Fatal error: Uncaught exception 'Zend_Config_Exception' with message 'parse_ini_file(/demo/application/configs/application.ini):
failed to open stream: No such file or directory' in /var/www/demo/library/Zend/Config/Ini.php:182
Stack trace:
#0 /var/www/demo/library/Zend/Config/Ini.php(202): Zend_Config_Ini->_parseIniFile('/demo/applicati...')
#1 /var/www/demo/library/Zend/Config/Ini.php(126): Zend_Config_Ini->_loadIniFile('/demo/applicati...')
#2 /var/www/demo/application/Bootstrap.php(32): Zend_Config_Ini->__construct('/demo/applicati...', 'development')
#3 /var/www/demo/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initDbAdapter()
#4 /var/www/demo/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('dbadapter')
#5 /var/www/demo/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL)
#6 /var/www/demo/library/Zend/Application.php(355): Zend_Application in /var/www/demo/library/Zend/Config/Ini.php on line 182