From 4782b1973979eecaf39dde4ab268d9a05c44c16b Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 17 Jun 2013 15:49:53 -0400 Subject: [PATCH] Better handling of sending response content. --- framework/yii/web/Response.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index e087a13..56e2b3e 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -319,7 +319,13 @@ class Response extends \yii\base\Response */ protected function sendContent() { - echo $this->content; + if (is_array($this->content)) { + echo 'array()'; + } elseif (is_object($this->content)) { + echo method_exists($this->content, '__toString') ? (string)$this->content : get_class($this->content); + } else { + echo $this->content; + } } /** @@ -723,13 +729,13 @@ class Response extends \yii\base\Response } switch ($this->format) { - case self::FORMAT_RAW: - $this->content = $this->data; - break; case self::FORMAT_HTML: $this->getHeaders()->setDefault('Content-Type', 'text/html; charset=' . $this->charset); $this->content = $this->data; break; + case self::FORMAT_RAW: + $this->content = $this->data; + break; case self::FORMAT_JSON: $this->getHeaders()->set('Content-Type', 'application/json'); $this->content = Json::encode($this->data);