将自定义配置文件加载到Codeigniter库中 [英] Loading custom config file into a Codeigniter library
本文介绍了将自定义配置文件加载到Codeigniter库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这可能很简单,但我没有。我已经创建了一个库,并且想从配置文件中加载参数。因此,这是我所拥有的示例:
I know this is probably simple, but I'm not getting. I've created a library, and I want to load the parameters from a config file. So here's an example of what I have:
// libraries/Mylib.php
class Mylib {
var $ci;
var $key;
public function _construct {
$this->ci =& get_instance();
$this->ci->config->load('mylib');
$this->key = $this->ci->config->item('key');
}
public function myKey() {
return "Key=" . $this->key;
}
}
// config/mylib.php
$config['key'] = 'randomcharacters';
我加载了库,并尝试打印出myKey函数,但它只返回 Key = ,没有实际的密钥。我缺少什么?
I load the library, and try to print out the myKey function, but it just returns "Key=", without the actual key. What am I missing?
推荐答案
似乎您错过了构造函数的下划线:
It seems like you missed an underscore for your constructor:
而不是
public function _construct () {
您应该使用
public function __construct () {
这篇关于将自定义配置文件加载到Codeigniter库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文