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 _cons开发者_如何学JAVAtruct {
$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';
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:
instead of
public function _construct () {
you should use
public function __construct () {
精彩评论