mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-30 06:29:02 +08:00
Better handling of sending response content.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user