Welcome Guest, Not a member yet? Register   Sign In
get_instance problem
#1

[eluser]JCianflone[/eluser]
Hi everyone,
I'm trying to create a new Exceptions class for a little project I'm working on but I seem to have an issue with getting the CodeIgniter instance. The error I get is:

Quote:Fatal error: Call to undefined function get_instance() in ...

My code is this:

Code:
class HUB_Exceptions extends CI_Exceptions {
    
    private $CI;
    
    public function __construct() {
        parent::CI_Exceptions();
        
        $this->CI =& get_instance(); //It breaks on this line here...

    }
}

This is my first time extending a core class, so I'm not 100% sure what's breaking here.

Any help would be greatly appreciated.

Thanks!
#2

[eluser]JoostV[/eluser]
You are extending the core. I think you can dirtectly refer to the CI superobject as $this.
#3

[eluser]JCianflone[/eluser]
Doesn't look like I can, I tried this:

Code:
$this->session->set_item('error_heading', $heading);

and got another error:

Quote:Fatal error: Call to a member function set_item() on a non-object in...
#4

[eluser]Shay Falador[/eluser]
Well, JoostV you are wrong, CI_Exceptions does not use the $this as we use it in controllers.

JCianflone, I guess the problem is that the Exceptions library is loaded BEFORE the base class is loaded and even it's filed loaded.
Therefor it doesn't exist yet..
#5

[eluser]JCianflone[/eluser]
Yea, that's what I was thinking.

OK, well, lets see if I can do this same thing with hooks!
#6

[eluser]JoostV[/eluser]
@shay You're right, did not read the question well.




Theme © iAndrew 2016 - Forum software by © MyBB