ExpressionEngine® 3 User Guide

Legacy Documentation

You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.

Output Class

The Output class is a core class with one main function: To send the finalized web page to the requesting browser. It is also responsible for caching web pages.

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 ExpressionEngine at the end of system execution. It is possible, however, for you to manually intervene with the output if you need to.

Class Reference

class EE_Output
property EE_Output::$parse_exec_vars

Defaults to TRUE.

Enables/disables parsing of the {elapsed_time} and {memory_usage} pseudo-variables.

ExpressionEngine will parse those tokens in your output by default. To disable this, set this property to FALSE in your controller.

ee()->output->parse_exec_vars = FALSE;
EE_Output::set_output($output)
Parameters:
  • $output (string) – String to set the output to
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

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

ee()->output->set_output($data);

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 methods, don’t set the output until the end.

EE_Output::get_output()
Returns:Output string
Return type:string

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

$string = ee()->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 ExpressionEngine functions like ee()->load->view().

EE_Output::append_output($output)
Parameters:
  • $output (string) – Additional output data to append
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

Appends data onto the output string.

ee()->output->append_output($data);
EE_Output::set_header($header[, $replace = TRUE])
Parameters:
  • $header (string) – HTTP response header
  • $replace (bool) – Whether to replace the old header value, if it is already set
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

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

ee()->output->set_header('HTTP/1.0 200 OK');
ee()->output->set_header('HTTP/1.1 200 OK');
ee()->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
ee()->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
ee()->output->set_header('Cache-Control: post-check=0, pre-check=0');
ee()->output->set_header('Pragma: no-cache');
EE_Output::set_status_header([$code = 200[, $text = '']])
Parameters:
  • $code (int) – HTTP status code
  • $text (string) – Optional message
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

Permits you to manually set a server status header. Example:

ee()->output->set_status_header('401');
// Sets the header as:  Unauthorized

See here for a full list of headers.

Note

This method is an alias for set_status_header().

EE_Output::enable_profiler([$val = TRUE])
Parameters:
  • $val (bool) – Whether to enable or disable the Profiler
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

Permits you to enable/disable the Output Debugger, 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 line anywhere within your Controller methods:

ee()->output->enable_profiler(TRUE);

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

To disable the profiler you would use:

ee()->output->enable_profiler(FALSE);
EE_Output::cache($time)
Parameters:
  • $time (int) – Cache expiration time in seconds
Returns:

EE_Output instance (method chaining)

Return type:

EE_Output

Caches the current page for the specified amount of seconds.

For more information, please see the caching documentation.

EE_Output::_display([$output = ''])
Parameters:
  • $output (string) – Output data override
Returns:

void

Return type:

void

Sends finalized output data to the browser along with any server headers. It also stops benchmark timers.

Note

This method is called automatically at the end of script execution, you won’t need to call it manually unless you are aborting script execution using exit() or die() in your code.

Note

Calling this method manually without aborting script execution will result in duplicated output.