1.默认简单的
Yii::$app->response->content = 'hello world!';
2.设置内容与样式规定的
如果在发送给终端用户之前需要格式化,应设置 format 和 data 属性,format 属性指定 data中数据格式化后的样式,例如:
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_JSON;
$response->data = ['message' => 'hello world'];
HTML:通过 yii\web\HtmlResponseFormatter 来实现。
XML:通过 yii\web\XmlResponseFormatter 来实现。
JSON:通过 yii\web\JsonResponseFormatter 来实现。
JSONP:通过 yii\web\JsonResponseFormatter 来实现。
RAW:如果要直接发送响应而不应用任何格式,请使用此格式