phpGrace 封装了 use grace\http\response 类用于响应输出。
功能 : 输出响应状态,当 404 时展示 404 页面 参数 : 状态码
<?php namespace grace\controller; use grace\grace; use grace\http\response; class index extends grace{ public function index(){ response::sendStatus(200); } }
功能 : 设置响应类型及字符集 参数1 : 类型 参数2 : 可选参数,字符集,默认 utf-8
'html' => 'text/html', 'text' => 'text/plain', 'xml' => 'text/xml', 'json' => 'application/json', 'pdf' => 'application/pdf', 'text' => 'text/plain', 'csv' => 'text/csv',
但 type 参数传递非预置值时, sendType() 函数将使用自定义类型,函数内部核心语法规则 :
header('content-type:'.$type);
<?php namespace grace\controller; use grace\grace; use grace\http\response; class index extends grace{ public function index(){ // 预置类型 response::setType('json'); // 自定义类型 //response::setType('application/zip;'); } }