Blogger Information
Blog 31
fans 0
comment 0
visits 24377
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Day44-2018/1/19(用四种方法实现请求对象的调用 )
SmallKing的博客
Original
785 people have browsed it

用四种方法实现请求对象的调用 
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());
    }

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post