Browse Source

Better handling of sending response content.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
4782b19739
  1. 12
      framework/yii/web/Response.php

12
framework/yii/web/Response.php

@ -319,8 +319,14 @@ class Response extends \yii\base\Response
*/
protected function sendContent()
{
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;
}
}
/**
* Sends a file to the browser.
@ -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);

Loading…
Cancel
Save