I’ve just started looking at hooks today not 100% sure what I’m doing wrong but I’m getting an error when I try and use the $ci object in my function.
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: hooks/language.php
Line Number: 12
My hooks file looks like this. It’s in the hooks directory in my application folder.
class Language{
var $ci;
public function __construct(){
$this->ci =& get_instance();
}
function get_language(){
echo $this->ci->session->userdata('language');
}
}
I need to get the value in the session to use in my function. Am I not supposed to do it like this?
Thanks you!
In the Base4/5.php file the get_instance() function is written and it is conditionally loaded so it won’t be present until after it is loaded. And that’s the reason its giving error.