CodeIgniter User Guide Version 1.5.3

Output Class

The Output class is a small class with one main function: To send the finalized web page to the requesting browser. It is also responsible for caching your web pages, if you use that feature.

Note: This class is initialized automatically by the system so there is no need to do it manually.

Under normal circumstances you won't even notice the Output class since it works transparently without your intervention. For example, when you use the Loader class to load a view file, it's automatically passed to the Output class, which will be called automatically by CodeIgniter at the end of system execution. It is possible, however, for you to manually intervene with the output if you need to, using either of the two following functions:


Permits you to manually set the final output string. Usage example:


Important: If you do set your output manually, it must be the last thing done in the function you call it from. For example, if you build a page in one of your controller functions, don't set the output until the end.


Permits you to manually retrieve any output that has been sent for storage in the output class. Usage example:

$string = $this->output->get_output();

Note that data will only be retrievable from this function if it has been previously sent to the output class by one of the CodeIgniter functions like $this->load->view().


Permits you to manually set server headers, which the output class will send for you when outputting the final rendered display. Example:

$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->output->set_header("Pragma: no-cache");


Permits you to enable/disable the Profiler, which will display benchmark and other data at the bottom of your pages for debugging and optimization purposes.

To enable the profiler place the following function anywhere within your Controller functions:


When enabled a report will be generated and inserted at the bottom of your pages.

To disable the profiler you will use: