为什么在Codeigniter更新(1.7.2至2.0.3)之后配置项调用返回错误

时间:2018-12-21 07:20:04

标签: php codeigniter codeigniter-2

我使用CI更新文档将应用程序从1.7.2更新到了2.0.3。 但是现在卡在了活动记录文件(application / libraries / Activerecord.php)中。

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

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

但是它返回一个错误。

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

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

已更新的CodeIgniter系统文件。, 更新了插件到助手。 更新了类扩展。 更新了父构造函数调用。 将核心扩展移至应用程序/核心。 更新配置文件夹更改。 索引文件已更改。

2 个答案:

答案 0 :(得分:1)

在您的库Activerecord.php中

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

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

将其更改为

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

答案 1 :(得分:0)

您需要重命名:

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

进入:

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

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

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