为什么在 Codeigniter 更新后配置项调用 return 错误(1.7.2 到 2.0.3)

Why the config item call return error after Codeigniter update(1.7.2 to 2.0.3)

我使用 CI 更新文档将我的应用程序从 1.7.2 更新到 2.0.3。 但现在我被活动记录文件中的一个错误所困(application/libraries/Activerecord.php).

在活动记录中,我尝试使用 $this->config 对象获取配置项。

我的代码:- $this->config->item('item_name');.

但它 return 一个错误。

错误:- 在 null 上调用成员函数 item()。

在 CI 更新期间,我根据 CI 文档做了以下操作。

更新了 CodeIgniter 系统文件。, 将插件更新为助手。 更新了 Class 个扩展。, 更新了父构造函数调用。 将核心扩展移动到 application/core., 更新配置文件夹更改。, 索引文件已更改。,

您需要重命名它:

require dirname( FILE ) . '/../../../config/your_custom_config.php';

进入这个:

require dirname( __FILE__ ) . '/your_custom_config.php';

并确保您正确设置了自定义配置路径。
或者,您可以在控制器中使用内置的配置加载器方法:

$this->config->load('your_custom_config');

在你的图书馆Activerecord.php

问题是...您不能使用 codeigniter 中可用的所有 类 .. 以执行加载配置...

$this->config->item('item_name');.

改为

$this->ci =& get_instance();
$this->ci->config->item('item_name');