Access to CodeIgniter Superobject causes PHP Error of Severity:Notice |
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
In the Auth_lib class, not $this->$CI but $this->CI.
Before crossing over to CodeIgniter4 i've used another solution that worked as well.
PHP Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |