views:

53

answers:

1

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 fucntion 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? Thanks!

+3  A: 

It seems like you missed an underscore for your constructor:

instead of

public function _construct {

you should use

public function __construct {
mseo
Good catch. It's only returning "Key=" because the `_construct` function never gets called. Therefore `$this->key` is still null.
treeface
Thank you!! I thought I was going insane. Also, I had a typo in the code... it should be $this->ci->load->config('mylib');
TerryMatula