1. 主页
  2. 文档
  3. THINKPHP6(官方)
  4. 请求对象和信息

请求对象和信息

1,依赖注入

2,$_GET[”];

3,  构造方式

4,门面的方式

5,助手函数

<?php
namespace app\controller;
use think\facade\Request;
//use think\Request;


class Qingqiu {
    protected $request;
    public function __construct(Request $request){
        $this->request=$request;
    }
    public function index(){
        return 'index';
    }
    // http://www.tp.com/public/index.php/qingqiu/qingqiu
    // /public/index.php/qingqiu/qingqiu
    public function qingqiu(){
        return Request::url();
    }
    // http://www.tp.com/public/index.php/qingqiu/shurubianliang/name/1111
    // 1111
    public function shurubianliang(){
        return Request::param('name');
        input('get.name','','htmlentities');
    }
    //依赖注入
    public function qingqiuleixing(Request $request){
        //http://www.tp.com/public/index.php/Qingqiu/qingqiuleixing?name=wulei
        return $request->param('name');
    }
    public function dayin(){
        //http://www.tp.com/public/index.php/Qingqiu/dayin?name=wulei
        return $_GET['name'];
    }
    //使用构造函数的写法
    //http://www.tp.com/public/index.php/Qingqiu/get?name=wulei
    public function get(){
        return $this->request->param('name');
    }
    //助手函数
    //http://www.tp.com/public/index.php/Qingqiu/helpfun?name=wulei
    public function helpfun(){
        return request()->param('name');
    }
    //门面调用  use think\facade\Request;
    //http://www.tp.com/public/index.php/Qingqiu/facadefun?name=wulei
    public function facadefun(){
        return Request::param('name');
    }
}
这篇文章对您有用吗?

我们要如何帮助您?