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 ';}}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号