thinkPHP5.1框架中Request类四种调用方式示例
程序员文章站
2022-06-03 13:04:11
本文实例讲述了thinkphp5.1框架中request类四种调用方式。分享给大家供大家参考,具体如下:
1. 传统调用
访问方式:http://127.0.0.1/d...
本文实例讲述了thinkphp5.1框架中request类四种调用方式。分享给大家供大家参考,具体如下:
1. 传统调用
访问方式:http://127.0.0.1/demo/demo3/test?name=kk&age=22
<?php /** * created by phpstorm. * user: 10475 * date: 2018/8/27 * time: 22:59 */ namespace app\demo\controller; use think\request; class demo3 { public function test() { $request = new request(); dump($request->get()); } }
2. 静态调用
request在thinkphp5.1中已经内置了静态代理类,可以直接使用
访问方式http://127.0.0.1/demo/demo3/test?name=kk&age=22&sex=male
<?php /** * created by phpstorm. * user: 10475 * date: 2018/8/27 * time: 22:59 */ namespace app\demo\controller; use think\facade\request; class demo3 { public function test() { dump(request::get()); } }
3. 依赖注入,也就是类型约束
访问方式http://127.0.0.1/demo/demo3/test?name=kk&age=22&sex=male
<?php /** * created by phpstorm. * user: 10475 * date: 2018/8/27 * time: 22:59 */ namespace app\demo\controller; use think\request; class demo3 { public function test(request $request) { dump($request->get()); } }
4. controller类中的request属性
<?php /** * created by phpstorm. * user: 10475 * date: 2018/8/27 * time: 22:59 */ namespace app\demo\controller; class demo3 extends \think\controller { public function test() { dump($this->request->get()); } }