CodeIgniter Forums
Using output in Custom Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using output in Custom Library (/thread-41580.html)



Using output in Custom Library - El Forum - 05-11-2011

[eluser]steviemo[/eluser]
Hi folks,

I have created a custom library and when I make a call to $this->output->set_status_header(404); I get PHP Fatal error: Call to a member function set_status_header() on a non-object.

I didn't think i needed to load the core output class in a custom library. A snapshot of the class is as follows:
Code:
class Rest {
    
    private $CI;

    function __construct() {
        $this->CI =& get_instance();
    }

     function response($data) {
        $this->output->set_status_header(404);
     }
}

If anyone has any ideas I'd appreciate it.

Thanks!


Using output in Custom Library - El Forum - 05-11-2011

[eluser]bubbafoley[/eluser]
you need to use the CI object you defined in the constructor

Code:
$this->CI->output->set_status_header(404);