Fatal exception in loading ini file

筅森魡賤 提交于 2019-12-07 20:37:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!