CodeIgniter Forums
Problems with Config file in custom Libarys [solved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problems with Config file in custom Libarys [solved] (/showthread.php?tid=3820)



Problems with Config file in custom Libarys [solved] - El Forum - 10-23-2007

[eluser]n8m[/eluser]
I read in the 1.5.4 User-Guide for Codeigniter, that variables and configuration can be passed to custom libraries. Somehow i have no luck with that. I tried both ways:

I try to pass values through the Controller that calls the Library by doing this:

Code:
$bla=array('foo'=>'ba');
   $this->load->library('widget',$bla);


also i tried to put the $bla stuff in a config file (which i am mainly interested in).

i tried to call the foo value in a method of my custom library the normal way like:

Code:
function test1(){
     echo $foo;
    }


What have i done wrong? Did i miss something?

Greetings and thanks in advance
n8m


Problems with Config file in custom Libarys [solved] - El Forum - 10-24-2007

[eluser]xwero[/eluser]
You can make a custom config file (config/widget.php) and you can autoload them or call them in the library
Code:
class Widget
{
    var $CI;

    function Widget()
    {
        $this->CI = & get_instance();
        $this->CI->load->config('widget');
    }
}



Problems with Config file in custom Libarys [solved] - El Forum - 10-24-2007

[eluser]n8m[/eluser]
Thanx for the feedback,
but it still doesen't work. My Config file looks like this:
Code:
$config['foo']="bar";

and my Library like this:
Code:
class Widget{
        
        public $CI;
        
        function Widget(){
            $this->CI = & get_instance();
                $this->CI->load->config('widget');
        }
        
        function dialog(){
                    
            echo $foo;
                }

The error message tells me that "Message: Undefined variable: foo".


Problems with Config file in custom Libarys [solved] - El Forum - 10-24-2007

[eluser]xwero[/eluser]
[quote author="n8m" date="1193235614"]Thanx for the feedback,
but it still doesen't work. My Config file looks like this:
Code:
$config['foo']="bar";

and my Library like this:
Code:
function dialog(){
                    
            echo $foo;
                }

[/quote]
You have to call it like you normally do
Code:
function dialog(){
                    
            echo $this->CI->config->item('foo');
                }



Problems with Config file in custom Libarys [solved] - El Forum - 10-24-2007

[eluser]n8m[/eluser]
Thnx .... that did it!