Welcome Guest, Not a member yet? Register   Sign In
Loading CI instance inside helper, causes problem in library?
#1

[eluser]tkrop[/eluser]
I have a custom library:

Code:
class CustomLib {
    var $CI;
    function CustomLib() {
        $this->CI =& get_instance();
    }

    private $user;
    function User() {
        if(!$this->user) { //ERROR IS AT THIS LINE, SEE BELOW...
            
        }
    }  
}

And I have a custom helper:

Code:
if ( ! function_exists('customhelper'))
{
    function customhelper() {
        $CI =& get_instance();
        
        switch($CI->customlib->User()->type) {
            case USERTYPE_ADMIN : {
                $bar = $CI->load->view('shared/menu_admin');
                break;
            }
            default : {
                $bar = $CI->load->view('shared/menu_guest');
                break;
            }
        }
        
        return $bar;
    }
}

But at the point where I call
Code:
$CI->load->view()
, it throws an error:

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$user
Filename: libraries/CustomLib.php
Line Number: SEE FIRST CODE EXAMPLE...


$this->user should only be checking CustomLib->user, and not the $CI->user right?? Am I doing something wrong here?

If I do print_r($this); then I see that it is a CustomLib object, however it still tries to access CustomLib->CI->user while I actually call CustomLib->user...


Messages In This Thread
Loading CI instance inside helper, causes problem in library? - by El Forum - 04-05-2010, 04:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB