Welcome Guest, Not a member yet? Register   Sign In
Custom Library Problem [solved]
#1

[eluser]n8m[/eluser]
Hi,

I've got a problem writing my own Libraries. Here's my Class:

Code:
class Aclass{
    
    function Aclass()
    {
    $CI=& get_instance();
    $CI->load->library('session');
        

    }
    
    function checksessionid()
    {

        $session_id = $CI->session->userdata('session_id');
        echo $session_id;
    }

}

The funny thing is, that it works when I put the Constructor lines into the method. Where's the error?

Thanks for your help
n8m
#2

[eluser]xwero[/eluser]
[quote author="n8m" date="1193154081"]Hi,

I've got a problem writing my own Libraries. Here's my Class:

Code:
class Aclass{
    
    function Aclass()
    {
    $CI=& get_instance();
    $CI->load->library('session');
        

    }
    
    function checksessionid()
    {

        $session_id = $CI->session->userdata('session_id');
        echo $session_id;
    }

}

The funny thing is, that it works when I put the Constructor lines into the method. Where's the error?

Thanks for your help
n8m[/quote]

The CI variable is only known in the scope of the constructor

Code:
class Aclass{
    
    var/public $CI;

    function Aclass()
    {
    $this->CI=& get_instance();
    $this->CI->load->library('session');
        

    }
    
    function checksessionid()
    {

        $session_id = $this->CI->session->userdata('session_id');
        echo $session_id;
    }

}
i didn't know which version of php you have that's why i used var(php4)/public(php5).
#3

[eluser]n8m[/eluser]
That did it !

Thnx !


greetz
n8m




Theme © iAndrew 2016 - Forum software by © MyBB