ThinPHP_5的请求和响应
Posted 高锴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ThinPHP_5的请求和响应相关的知识,希望对你有一定的参考价值。
thinkphp的请求对象request
所有请求的参数都可以通过request接收
方法一:
request();助手函数
方法二:
use think\Request;
Request::instance();[Resquest是单利模式折,只能通过instence获取实例]
方法三:
直接注入到方法,给index方法传参,参数类型Request对象,起个名称,$request[推荐使用]
use think\Request;
public function index(Request $request)
{
dump($request);
}
响应对象Response
// 默认输出类型【惯例配置】
‘default_return_type‘ => ‘html‘,
if(!in_array($type,[‘json‘,‘jsonp‘,‘xml‘])){
$type = ‘json‘;
}
//动态配置默认输出类型
Config::set(‘default_return_type‘,$type);
以上是关于ThinPHP_5的请求和响应的主要内容,如果未能解决你的问题,请参考以下文章