博客列表 >Day44-2018/1/19(用四种方法实现请求对象的调用 )

Day44-2018/1/19(用四种方法实现请求对象的调用 )

SmallKing的博客
SmallKing的博客原创
2018年01月20日 18:10:56777浏览

用四种方法实现请求对象的调用 
1. new

<?php
namespace app\index\controller;


use think\Request;

//1.实例化类获取信息
class Demo1
{
    public function test()
    {
        dump((new Request())->param()) ;

    }

}

2. facade

<?php
namespace app\index\controller;

use think\Facade\Request;

//2.通过静态代理的方式访问获取信息
class Demo2
{
    public function test()
    {
        dump(Request::param()) ;

    }

}

3. Requst $request

<?php
namespace app\index\controller;



//3.通过依赖注入的方式访问获取信息
class Demo3
{
    public function test(\think\Request $test)
    {
        dump($test->param()) ;
    }

}

4. $this->request

<?php
namespace app\index\controller;
use think\Controller;
//通过继承父类获取信息

class Demo4 extends Controller
{
    public function test()
    {
        dump($this->request->param());
    }

}


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议