Welcome Guest, Not a member yet? Register   Sign In
Config items in Libraries
#1

[eluser]rob897[/eluser]
Is this by design but when I try to echo out config values within a custom library I get the following error:
Undefined property: Directories::$config

All I am trying to do is echo out this value below:
$this->config->item('mailto');

thanks
-rob
#2

[eluser]xwero[/eluser]
in a custom library you need to get the CI object which you can do using the get_instance function. You can put it in the constructor of the library or in the method.
Code:
$_ci =& get_instance();
$_ci->config->item('mailto');
#3

[eluser]rob897[/eluser]
Ok thats getting me closer, I added the get_instance into the constructor as follows:

Code:
function __construct()
    {
        $ci = & get_instance();
        $ci->config->item('mailto');
    }

But how do I echo this value across the methods in this class say:

Code:
function display()
       {
              echo $ci->config->item('mailto');
       }

Sorry a little new to OOP.

thanks

-rob
#4

[eluser]xwero[/eluser]
If you want to add it to the constructor and use it in multiple methods you can use a class variable
Code:
class FantasticLibrary
{

   private $ci;

   function __construct()
   {
     $this->ci =& get_instance();
   }

   function display()
   {
     $this->ci->config->item('mailto');
   }

}




Theme © iAndrew 2016 - Forum software by © MyBB