From d76334998db618d4633886bbcecc84658b50ab23 Mon Sep 17 00:00:00 2001
From: Derek Jones
Date: Tue, 28 Sep 2010 13:14:57 -0500
Subject: fixed a bug where the Output class would send incorrect cached data
for controllers implementing their own _output() methods
---
system/core/Output.php | 21 +++++++++++++--------
user_guide/changelog.html | 1 +
user_guide/general/controllers.html | 11 ++++++++++-
3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/system/core/Output.php b/system/core/Output.php
index 7d3e2e180..ad9ffbabe 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -212,7 +212,13 @@ class CI_Output {
// since this function is sometimes called by the caching mechanism,
// which happens before the CI super object is available.
global $BM, $CFG;
-
+
+ // Grab the super object if we can.
+ if (function_exists('get_instance'))
+ {
+ $CI =& get_instance();
+ }
+
// --------------------------------------------------------------------
// Set the output data
@@ -223,8 +229,10 @@ class CI_Output {
// --------------------------------------------------------------------
- // Do we need to write a cache file?
- if ($this->cache_expiration > 0)
+ // Do we need to write a cache file? Only if the controller does not have its
+ // own _output() method and we are not dealing with a cache file, which we
+ // can determine by the existence of the $CI object above
+ if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
{
$this->_write_cache($output);
}
@@ -271,10 +279,10 @@ class CI_Output {
// --------------------------------------------------------------------
- // Does the get_instance() function exist?
+ // Does the $CI object exist?
// If not we know we are dealing with a cache file so we'll
// simply echo out the data and exit.
- if ( ! function_exists('get_instance'))
+ if ( ! isset($CI))
{
echo $output;
log_message('debug', "Final output sent to browser");
@@ -283,9 +291,6 @@ class CI_Output {
}
// --------------------------------------------------------------------
-
- // Grab the super object. We'll need it in a moment...
- $CI =& get_instance();
// Do we need to generate profile data?
// If so, load the Profile class and run it.
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index fb533b082..58fd78008 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -162,6 +162,7 @@ Hg Tag:
Bug fixes for 2.0.0
+ - Fixed a bug where the Output class would send incorrect cached output for controllers implementing their own _output() method.
- Fixed a bug where a failed query would not have a saved query execution time causing errors in the Profiler
- Fixed a bug that was writing log entries when multiple identical helpers and plugins were loaded.
- Fixed assorted user guide typos or examples (#10693, #8951, #7825, #8660, #7883, #6771, #10656).
diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html
index 9658df876..2020011d9 100644
--- a/user_guide/general/controllers.html
+++ b/user_guide/general/controllers.html
@@ -268,7 +268,16 @@ function _output($output)
Please note that your _output() function will receive the data in its finalized state. Benchmark and memory usage data will be rendered,
cache files written (if you have caching enabled), and headers will be sent (if you use that feature)
-before it is handed off to the _output() function. If you are using this feature the page execution timer and memory usage stats might not be perfectly accurate
+before it is handed off to the _output() function.
+
+To have your controller's output cached properly, its _output() method can use:
+
+if ($this->output->cache_expiration > 0)
+{
+ $this->output->write_cache($output);
+}
+
+If you are using this feature the page execution timer and memory usage stats might not be perfectly accurate
since they will not take into acccount any further processing you do. For an alternate way to control output before any of the final processing is done, please see
the available methods in the Output Class.
--
cgit v1.2.3-24-g4f1b