Welcome Guest, Not a member yet? Register   Sign In
Access to CodeIgniter Superobject causes PHP Error of Severity:Notice
#1

I have a CodeIgniter library. When I access it from my controller a PHP Error of Severity:Notice is generated. However, the debugger shows that the super object exists in the library and is the CI super object.

Here is the library class:

    class Auth_lib {

    protected $CI;

    public function __construct()
    {
        $this->$CI =& get_instance();
        $this->$CI->load->model('auth_model');
        $this->$CI->load->library('session');
    }

    /**
    * checks if the current user is logged into a session
    * @param
    * @return boolean
    */
    public function is_logged_in(){
        $result = $this->$CI->session->userdata('is_logged_in');
        return $result;
    }
}
And this is how the library is called from my controller:

        public function __construct()
        {
            parent::__construct();
            $this->load->helper('url_helper');
            $this->load->library('auth_lib');

            // test if user is logged in and authorised, if not redirect to login controller

            if($this->auth_lib->is_logged_in() != null){
                // check if is admin
                }
            } else {
                // not logged in, redirect to login controller
            }

        }
So, why I am getting this error:

A PHP Error was encountered Severity: Notice Message: Undefined variable: CI Filename: libraries/Auth_lib.php Line Number: 20
Reply


Messages In This Thread
Access to CodeIgniter Superobject causes PHP Error of Severity:Notice - by BobbyTanomred - 12-22-2022, 02:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB