Welcome Guest, Not a member yet? Register   Sign In
Problems with Config file in custom Libarys [solved]
#1

[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
#2

[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');
    }
}
#3

[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".
#4

[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');
                }
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB