yii2 http响应头小方法

$res = \YII::app->respons; //响应头部类文件
$res->statusCode='404'; //设置状态码


$res->header->add('pragma','no-cache');  //浏览器缓存,不把消息缓存在浏览器中
$res->header->set('pragma','max-age=5'); //修改头部信息
$res->header->remove('pragma'); //删除

$res->header->add('location','www.zzhy.com'); //跳转
$this->redirect('www.zzhy.com','302');//访问此方法默认跳转到此域名下
//文件下载
$res->header->add('content-disposition','attachment;filename="a.text"'); //以附件的形式把数据保存在a.text中
$res->sendFile('/a.jpg'); //把a.jpg通过浏览器下载(根目录默认为web文件夹下)




猜你喜欢

转载自blog.csdn.net/zhangzhangdan/article/details/81016749