From 056e54785514d2d724445f24f304d429e8a4e696 Mon Sep 17 00:00:00 2001 From: Ben Corlett Date: Thu, 17 May 2012 11:47:10 +1000 Subject: [PATCH 1/3] Adding output buffering to allow redirects to work after content has been outputted. Signed-off-by: Ben Corlett --- laravel/core.php | 14 ++++++++++++++ laravel/redirect.php | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/laravel/core.php b/laravel/core.php index 0dcaaca5..e59e8c0b 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -17,6 +17,20 @@ define('DEFAULT_BUNDLE', 'application'); 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 diff --git a/laravel/redirect.php b/laravel/redirect.php index 2678f445..0f47cff8 100644 --- a/laravel/redirect.php +++ b/laravel/redirect.php @@ -165,4 +165,23 @@ public function with_errors($container) 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(); + } + } \ No newline at end of file From 33fdcb4ae7dbbeef851b84ff3fe888ef73186645 Mon Sep 17 00:00:00 2001 From: Ben Corlett Date: Thu, 17 May 2012 13:02:57 +1000 Subject: [PATCH 2/3] Fixing type-o with the spelling of "Symfony". Signed-off-by: Ben Corlett --- laravel/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laravel/core.php b/laravel/core.php index e59e8c0b..f32e40af 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -24,7 +24,7 @@ | | 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 +| echoed a string, but want to return a Redirect object. Because Symfony | only checks if headers have been sent, your redirect just silently fails. | */ From 7f0d709b3bcfa48019059708d7530166bff6646b Mon Sep 17 00:00:00 2001 From: Ben Corlett Date: Tue, 29 May 2012 11:26:27 +1000 Subject: [PATCH 3/3] Adding mb_output_handler as the default callback for output buffering, Thanks @syntaqx --- laravel/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laravel/core.php b/laravel/core.php index f32e40af..202d81b1 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -29,7 +29,7 @@ | */ -ob_start(); +ob_start('mb_output_handler'); /* |--------------------------------------------------------------------------