Browse Source

Adding output buffering to allow redirects to work after content has been outputted.

Signed-off-by: Ben Corlett <bencorlett@me.com>
Ben Corlett 12 years ago
parent
commit
056e547855
2 changed files with 33 additions and 0 deletions
  1. 14 0
      laravel/core.php
  2. 19 0
      laravel/redirect.php

+ 14 - 0
laravel/core.php

@@ -17,6 +17,20 @@ define('BLADE_EXT', '.blade.php');
 define('DEFAULT_BUNDLE', 'application');
 define('DEFAULT_BUNDLE', 'application');
 define('MB_STRING', (int) function_exists('mb_get_info'));
 define('MB_STRING', (int) function_exists('mb_get_info'));
 
 
+/*
+|--------------------------------------------------------------------------
+| Start Output Buffering
+|--------------------------------------------------------------------------
+|
+| Output buffering allows us to capture all output at any time, so that we
+| can discard it or treat it accordingly. An example of this is if you have
+| echoed a string, but want to return a Redirect object. Because Symphony
+| only checks if headers have been sent, your redirect just silently fails.
+|
+*/
+
+ob_start();
+
 /*
 /*
 |--------------------------------------------------------------------------
 |--------------------------------------------------------------------------
 | Require Core Classes
 | Require Core Classes

+ 19 - 0
laravel/redirect.php

@@ -165,4 +165,23 @@ class Redirect extends Response {
 		return $this->with('errors', $errors);
 		return $this->with('errors', $errors);
 	}
 	}
 
 
+	/**
+	 * Send the headers and content of the response to the browser.
+	 *
+	 * @return void
+	 */
+	public function send()
+	{
+		// Dump all output buffering, this ensures
+		// that symphony will send our redirect headers
+		// properly if we've outputted any content from
+		// within Laravel.
+		while (ob_get_level() > 0)
+		{
+			ob_end_clean();
+		}
+
+		return parent::send();
+	}
+
 }
 }