Welcome Guest, Not a member yet? Register   Sign In
Trying to extend output lib : Call to undefined function get_instance()
#1

[eluser]louis w[/eluser]
I am trying to extend the output library but getting an error when trying to call get_instance. Not sure why this would be happening, I have never run up against this issue in other libraries.

Code:

Code:
class MY_Output extends CI_Output {

    public function __construct() {

            parent::__construct();

            $this->CI =& get_instance();
            
    }
    
    // ...
    
}

Error:

Code:
Fatal error: Call to undefined function get_instance() in /.../application/libraries/MY_Output.php

And I should mention that I have the native CI caching turned off, so it's not loading the output library before creating the super object.
#2

[eluser]louis w[/eluser]
Anyone at Ellis know why this would happen? Is there a possible way around it?
#3

[eluser]Pascal Kriete[/eluser]
I do actually Smile .

The output library is instantiated before the super object exists (or the get_instance function for that matter). The reasoning behind this is that you want to load as little as possible before the caching hook is called.

What part of the super object do you need?
#4

[eluser]louis w[/eluser]
Hi Pascal, thanks for the reply.
I need to be able to access config and load views from my output library. It's a robust template/site output library.

I finally just made an initialize method in MY_Output and added if (!$this->_int) $this->_initialize(); to my other methods. Not the most elegant solution, but it works. Only way I could get around CI not being loaded at the point of the constructor.




Theme © iAndrew 2016 - Forum software by © MyBB