Welcome Guest, Not a member yet? Register   Sign In
Probably a simple issue: Loading custom config file into a library
#1

[eluser]matula[/eluser]
Here's an example of the code I have so far:
Code:
// 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';

But when I try to print out the myKey function, it just says "Key=" without the actual key. I checked the docs, and I'm sure I'm just missing something.
Thanks!
#2

[eluser]kaejiavo[/eluser]
Try:
Code:
$this->ci->load->config('mylib', TRUE);
$this->ci->config->item('key', 'mylib');

edit: also you have an error in your syntax, correct is: ci->load->config

Marco
#3

[eluser]matula[/eluser]
Thanks! The typo was one problem, but I also found out I didn't have two "_" before the constructor.




Theme © iAndrew 2016 - Forum software by © MyBB