问题
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);
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
回答1:
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.
回答2:
Some time this error occurs due to auto created file
application.ini~ in hidden mode on same path
/demo/application/configs/ So please check hidden file on same path
like /demo/application/configs/application.ini~ if found then remove it.
回答3:
I solved it by changing the config file param to APPLICATION_PATH.''/configs/application.ini
来源:https://stackoverflow.com/questions/16840860/fatal-exception-in-loading-ini-file