From 52fe7bb68f9961cdd765dd38e54779ae3b66e586 Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Sun, 1 Apr 2012 11:43:20 +0700 Subject: add function get_current_content_type to output class and user manual library --- system/core/Output.php | 18 ++++++++++++++++++ user_guide_src/source/libraries/output.rst | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/system/core/Output.php b/system/core/Output.php index 9bf818e88..673ceb0ee 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,6 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } + + // -------------------------------------------------------------------- + + /** + * Get Current Content Type Header + * Return text/html if Content-Type is not set + * + * @return string + */ + public function get_current_content_type() + { + foreach($this->headers as $header){ + if(preg_match('/^Content-Type/', $header[0])){ + return str_replace('Content-Type: ', '', $header[0]); + } + } + return 'text/html'; + } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 2cf7c0854..8cd5ff895 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -49,6 +49,13 @@ data, JPEG's, XML, etc easily. .. important:: Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect. +$this->output->get_current_content_type(); +==================================== + +Get the current mime-type of your page and return 'text/html' by default. + + $this->output->get_current_content_type(); + $this->output->get_output(); ============================= -- cgit v1.2.3-24-g4f1b