加载ini文件时发生致命异常 [英] Fatal exception in loading ini file
问题描述
我的项目文件夹为demo,其中包含应用程序,库和公共文件夹.在应用程序文件夹中,我有一个名为configs的文件夹,其中有一个文件'application.ini',其中包含我的数据库参数.因此,在应用程序目录中的bootstrap.php中,我在名为_initDbAdapter
:
My project folder is demo, inside which I have the folders application, library and public. Inside the application folder, I have a folder named configs, inside which I have a file 'application.ini', which contains my database parameters. So, in the bootstrap.php which is in application directory, I set my database in Zend registry in a function called _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位于公共文件夹中),出现以下错误:
When I point my browser to localhost/demo/public/ (since my index.php resides in the public folder), I get the following error:
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
推荐答案
由于/demo/application/configs/application.ini
不是正确的路径,因此出现此错误.查看您的错误,完整的绝对路径为/var/www/demo/application/configs/application.ini
,但是您可能想使用APPLICATION_PATH.'/configs/application.ini'
,这是更方便的快捷方式.
You're getting this error because /demo/application/configs/application.ini
is not the correct path. Looking at your errors, the full absolute path is /var/www/demo/application/configs/application.ini
but you probably want to use APPLICATION_PATH.'/configs/application.ini'
which is a more convenient shortcut.
这篇关于加载ini文件时发生致命异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!