diff options
author | Brennan Thompson <brenjt@gmail.com> | 2014-02-14 20:03:57 +0100 |
---|---|---|
committer | Brennan Thompson <brenjt@gmail.com> | 2014-02-14 20:03:57 +0100 |
commit | 6949f95f6e21980f36095490bf38fc8a172dbc0f (patch) | |
tree | b3141f390acd0051396cda6a3da51c1f98384cca /user_guide_src/source/libraries/output.rst | |
parent | 68a02a01a086bbb1b8128ea2744439de84873d11 (diff) | |
parent | 81f036753272391360ba5b64e6dd93c4101a8733 (diff) |
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts:
system/helpers/form_helper.php
Diffstat (limited to 'user_guide_src/source/libraries/output.rst')
-rw-r--r-- | user_guide_src/source/libraries/output.rst | 242 |
1 files changed, 138 insertions, 104 deletions
diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index a3d67b847..e49ea5366 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -2,7 +2,7 @@ Output Class ############ -The Output class is a small class with one main function: To send the +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 :doc:`caching <../general/caching>` your web pages, if you use that feature. @@ -16,159 +16,193 @@ use the :doc:`Loader <../libraries/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: +need to. -$this->output->set_output(); -============================= +.. contents:: + :local: -Permits you to manually set the final output string. Usage example:: +.. raw:: html - $this->output->set_output($data); + <div class="custom-index container"></div> -.. 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. +*************** +Class Reference +*************** -$this->output->set_content_type(); -==================================== +.. class:: CI_Output -Permits you to set the mime-type of your page so you can serve JSON -data, JPEG's, XML, etc easily. + .. attribute:: $parse_exec_vars = TRUE; -:: + Enables/disables parsing of the {elapsed_time} and {memory_usage} pseudo-variables. - $this->output - ->set_content_type('application/json') - ->set_output(json_encode(array('foo' => 'bar'))); + CodeIgniter will parse those tokens in your output by default. To disable this, set + this property to FALSE in your controller. + :: - $this->output - ->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php - ->set_output(file_get_contents('files/something.jpg')); + $this->output->parse_exec_vars = FALSE; -.. important:: Make sure any non-mime string you pass to this method - exists in config/mimes.php or it will have no effect. + .. method:: set_output($output) -You can also set the character set of the document, by passing a second argument:: + :param string $output: String to set the output to + :returns: CI_Output instance (method chaining) + :rtype: CI_Output - $this->output->set_content_type('css', 'utf-8'); + Permits you to manually set the final output string. Usage example:: -$this->output->get_content_type() -================================= + $this->output->set_output($data); -Returns the Content-Type HTTP header that's currently in use, -excluding the character set value. + .. 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. - $mime = $this->output->get_content_type(); + .. method:: set_content_type($mime_type[, $charset = NULL]) -.. note:: If not set, the default return value is 'text/html'. + :param string $mime_type: MIME Type idenitifer string + :param string $charset: Character set + :returns: CI_Output instance (method chaining) + :rtype: CI_Output -$this->output->get_header() -=========================== + Permits you to set the mime-type of your page so you can serve JSON data, JPEG's, XML, etc easily. + :: -Gets the requested HTTP header value, if set. + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(array('foo' => 'bar'))); -If the header is not set, NULL will be returned. -If an empty value is passed to the method, it will return FALSE. + $this->output + ->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php + ->set_output(file_get_contents('files/something.jpg')); -Example:: + .. important:: Make sure any non-mime string you pass to this method + exists in *application/config/mimes.php* or it will have no effect. - $this->output->set_content_type('text/plain', 'UTF-8'); - echo $this->output->get_header('content-type'); - // Outputs: text/plain; charset=utf-8 + You can also set the character set of the document, by passing a second argument:: -.. note:: The header name is compared in a case-insensitive manner. + $this->output->set_content_type('css', 'utf-8'); -.. note:: Raw headers sent via PHP's native ``header()`` function are - also detected. + .. method:: get_content_type() -$this->output->get_output() -=========================== + :returns: Content-Type string + :rtype: string -Permits you to manually retrieve any output that has been sent for -storage in the output class. Usage example:: + Returns the Content-Type HTTP header that's currently in use, excluding the character set value. + :: - $string = $this->output->get_output(); + $mime = $this->output->get_content_type(); -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(). + .. note:: If not set, the default return value is 'text/html'. -$this->output->append_output(); -================================ + .. method:: get_header($header) -Appends data onto the output string. Usage example:: + :param string $header: HTTP header name + :returns: HTTP response header or NULL if not found + :rtype: mixed - $this->output->append_output($data); + Returns the requested HTTP header value, or NULL if the requested header is not set. + Example:: -$this->output->set_header(); -============================= + $this->output->set_content_type('text/plain', 'UTF-8'); + echo $this->output->get_header('content-type'); + // Outputs: text/plain; charset=utf-8 -Permits you to manually set server headers, which the output class will -send for you when outputting the final rendered display. Example:: + .. note:: The header name is compared in a case-insensitive manner. - $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"); - $this->output->set_header("Pragma: no-cache"); + .. note:: Raw headers sent via PHP's native ``header()`` function are also detected. -$this->output->set_status_header(code, 'text'); -================================================= + .. method:: get_output() -Permits you to manually set a server status header. Example:: + :returns: Output string + :rtype: string - $this->output->set_status_header('401'); - // Sets the header as: Unauthorized + Permits you to manually retrieve any output that has been sent for + storage in the output class. Usage example:: -`See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for -a full list of headers. + $string = $this->output->get_output(); -.. note:: This method is an alias for :doc:`Common function <../general/common_functions>` - ``set_status_header()``. + 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()``. -$this->output->enable_profiler(); -================================== + .. method:: append_output($output) -Permits you to enable/disable the -:doc:`Profiler <../general/profiling>`, which will display benchmark -and other data at the bottom of your pages for debugging and -optimization purposes. + :param string $output: Additional output data to append + :returns: CI_Output instance (method chaining) + :rtype: CI_Output -To enable the profiler place the following function anywhere within your -:doc:`Controller <../general/controllers>` functions:: + Appends data onto the output string. + :: - $this->output->enable_profiler(TRUE); + $this->output->append_output($data); -When enabled a report will be generated and inserted at the bottom of -your pages. + .. method:: set_header($header[, $replace = TRUE]) -To disable the profiler you will use:: + :param string $header: HTTP response header + :param bool $replace: Whether to replace the old header value, if it is already set + :returns: CI_Output instance (method chaining) + :rtype: CI_Output - $this->output->enable_profiler(FALSE); + 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_profiler_sections(); -========================================= + $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'); + $this->output->set_header('Pragma: no-cache'); -Permits you to enable/disable specific sections of the Profiler when -enabled. Please refer to the :doc:`Profiler <../general/profiling>` -documentation for further information. + .. method:: set_status_header([$code = 200[, $text = '']]) -$this->output->cache(); -======================= + :param int $code: HTTP status code + :param string $text: Optional message + :returns: CI_Output instance (method chaining) + :rtype: CI_Output -The CodeIgniter output library also controls caching. For more -information, please see the :doc:`caching -documentation <../general/caching>`. + Permits you to manually set a server status header. Example:: -Parsing Execution Variables -=========================== + $this->output->set_status_header('401'); + // Sets the header as: Unauthorized -CodeIgniter will parse the pseudo-variables {elapsed_time} and -{memory_usage} in your output by default. To disable this, set the -$parse_exec_vars class property to FALSE in your controller. -:: + `See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for a full list of headers. - $this->output->parse_exec_vars = FALSE; + .. note:: This method is an alias for :doc:`Common function <../general/common_functions>` + :func:`set_status_header()`. + .. method:: enable_profiler([$val = TRUE]) + + :param bool $val: Whether to enable or disable the Profiler + :returns: CI_Output instance (method chaining) + :rtype: CI_Output + + Permits you to enable/disable the :doc:`Profiler <../general/profiling>`, 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 + :doc:`Controller <../general/controllers>` methods:: + + $this->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:: + + $this->output->enable_profiler(FALSE); + + .. method:: set_profiler_sections($sections) + + :param array $sections: Profiler sections + :returns: CI_Output instance (method chaining) + :rtype: CI_Output + + Permits you to enable/disable specific sections of the Profiler when it is enabled. + Please refer to the :doc:`Profiler <../general/profiling>` documentation for further information. + + .. method:: cache($time) + + :param int $time: Cache expiration time in seconds + :returns: CI_Output instance (method chaining) + :rtype: CI_Output + + Caches the current page for the specified amount of seconds. + + For more information, please see the :doc:`caching documentation <../general/caching>`.
\ No newline at end of file |