CodeIgniter Forums
Hooking display_override - $this->output->get_output not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Hooking display_override - $this->output->get_output not working (/showthread.php?tid=7986)



Hooking display_override - $this->output->get_output not working - El Forum - 04-30-2008

[eluser]Stuart Marsh[/eluser]
I'm trying to use the display_override hook to edit output before it gets to the user.
I created the following hook:
Code:
class display_hook {
    
    function NewOutput()
    {
        $content = $this->output->get_output();        
    }
}
In the manual it syas that $this->output->get_output() should work but it doesn't.
I get this error:
Code:
Message: Undefined property: Display_Hook::$output
Call to a member function _display() on a non-object
So I then tried this code:
Code:
class display_hook extends Controller {
    
    function NewOutput()
    {
        $content = $this->output->get_output();        
    }
}
This works but creates another problem. When I try to load a model in a controller is gives me this error:
Code:
Message: Undefined property: Display_Hook::$DB_Content
Fatal error: Call to a member function _assign_libraries() on a non-object

So I have two questions:
1 - What is the correct format for a hook class so I can use $this->output->get_output()?
2 - Why can't I load a model when I extend the controller for my hook?

Any help would be appreciated.


Hooking display_override - $this->output->get_output not working - El Forum - 07-29-2008

[eluser]Unknown[/eluser]
Are you ensuring that you make a reference to the CI superobject before you make a call to get_output on it? i.e.:

Code:
$this->CI =& get_instance();
$this->CI->output->get_output();



Hooking display_override - $this->output->get_output not working - El Forum - 07-29-2008

[eluser]Stuart Marsh[/eluser]
oops should have updated this.
I posted this as a bug here: http://codeigniter.com/bug_tracker/bug/4512/
The manual used to say that $this->output->get_output() would work, but has since been changed to reflect the correct code.