1.传统的new Request
2.静态代理:think\facade\Request;
3.依赖注入:Request $request;
4.父类Controller中的属性$request : this->request->get();
注:
<?php
//导入请求对象的静态代理
//use think\Facade\Request;
//引用动态类
use think\Request;
namespace app\index\controller;
use think\Container;
use function MongoDB\BSON\toJSON;
class Demo3 extends Container
{
public function test()
{
// dump(Request::get());
// $request = new Request();
// dump($this->request->get());
//以Json方式输出
return json_encode($this->request->get());
// return 'hello php.cn ';
}
}