CodeIgniter中数据库的问题 [英] Problem with database in CodeIgniter
问题描述
我下载了CodeIgniter的最后一个版本,我试图运行一个简单的应用程序。代码完全没有数据库,但是当我添加这个
I downloaded the last version of CodeIgniter and I tried to run a simple app. The code works perfectly without database, but when I added this
$autoload['libraries'] = array('database');
页面变为空白。
我看了日志文件,但我没有找到任何东西,我检查不同的教程,但我的database.php文件看起来正确配置。我从数组中删除它。
I looked at the logs files but I didn't find anything, I check differents tutorial, but my database.php file looks correctly configured. I removed it from the array.
$autoload['libraries'] = array('');
并添加到控制器中:
$this->load->library('database');
然后,出现此错误
An Error was encountered
Unable to load the requested class: database
我做什么?任何线索?
提前感谢
推荐答案
你需要使用'库'自动加载而不是'config'自动加载
To use the database you need to use the 'library' autoload instead of the 'config' auto load
$autoload['libraries'] = array('database');
这将自动加载您的配置。
This will actually automatically load up your configurations.
UPDATE
您在问题中提到的另一件事是,您'添加'该行,您不需要添加该行,您可以将元素添加到该行上已经存在的数组中。您可能会覆写其他自动加载的程式库,我需要查看您的 autoload.php
档案才能确认。
Another thing you mention in your question is that you 'add' that line, you do not need to add that line, you are suppose to add the element to the array that already exists on that line. You potentially could be overwriting other autoloaded libraries, I will need to see your autoload.php
file to confirm this.
这篇关于CodeIgniter中数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!