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);

posted @ 2017-07-04 23:02  高锴  阅读(367)  评论(0编辑  收藏  举报