CodeIgniter和自动加载数据库库 [英] CodeIgniter and autoloading the database library

查看:45
本文介绍了CodeIgniter和自动加载数据库库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CodeIgniter连接数据库时出现问题。

I've got an issue connecting to the database with CodeIgniter.

在模型中,如果我这样做

In the model, if I do

$this->load->database();

然后查询诸如

$query = $this->db->get('articles', 10);

工作并返回数据。但是,当我删除load-> database行并尝试自动加载数据库库时,使用

works and returns data. However, when I remove the load->database line and try autoloading the database library, using

$autoload['libraries'] = array('database');

在application / config / autoload.php中,上述查询失败。当我显式加载库时,它可以正常工作,这与数据库连接无关。我正在使用CodeIgniter 2.0.2(当前最新版本)。

in application/config/autoload.php, the above query fails. As it works when I explicitly load the library, it's not a problem with my database connection. I'm using CodeIgniter 2.0.2 (the current latest release).

由于我的大多数页面都使用数据库,因此我想自动加载该数据库以避免加载每年在每个模型中。我是否误解了有关加载数据库库的文档,或者我做错了什么?

As most of my pages use the database I'd like to autoload it to avoid having to load it anually in each model. Have I misunderstood the documentation regarding loading the database library or am I doing something wrong?

推荐答案

我知道我可能只是在回答一个死的问题,但我有同样的问题。

I know I am probably just answering a dead question but i had the same problem.

如果您使用的是eclipse pdt或类似的IDE,并通过在变量之前添加一些变量来修改system> core> model.php。构造函数获取代码完成,然后自动加载不起作用

if you are using eclipse pdt or similar IDE and modified the system>core>model.php by adding some variables just before the constructor to get code completion then the autoload doesnt work

我不知道为什么,但是事实是它不起作用。我将core> model.php恢复到原始状态,并且自动加载正常。我现在没有自动加载功能,对于将新编码器转换为CI来说,这确实是一个糟糕的体验。

i dont know why but the fact is it doesnt work. I restored the core>model.php to original and autoload works fine. I dont get autoload now and its really a bad experience for new coder to CI.

如果您有解决方法,请发表评论。

If you have a workaround please comment so.

这篇关于CodeIgniter和自动加载数据库库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆