谈箔撮每惨扔啪位储花粱客妊
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } }
执行:
Request请求类的位置:D:\phpStudy\PHPTutorial\WWW\tp5\thinkphp\library\think\Request.php
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的get请求变量 dump($request->get()); } }
执行,通过get传参的形式访问hello()
通过get传参的形式访问demo
获取post请求
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->post()); } }
执行:
模拟post请求
param()可以获取所有请求类型包括get,post,path_info等
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->param()); } }
获取gei()传递的数据
获取post提交的数据
tp5推荐使用param获取参数
获取name值
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->param("name")); } }
执行:
has()检查是否存在请求变量
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->has("name")); } }
执行:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->has("salary")); } }
执行:
1.获取域名
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->domain()); } }
执行:
2.获取URL,不包括域名
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->url()); } }
执行:
3.传入参数true,包含域名:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function inedx($name) { return "萌面人资料铺"; } public function hello($name,$lession) { return "我是".$name."正在学习".$lession."课程"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->url(true)); } }
执行:
4.path_info()
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->pathinfo()); } }
执行:
url请求加后缀
5.path()方法不包括后缀
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->path()); } }
执行:
6.ext()只返回后缀信息
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->ext()); } }
执行:
7.module()查看当前访问的模块
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->module()); } }
执行:
8.controller查看当前的控制器
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->controller()); } }
执行:
9.action()查看当前的操作
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 dump($request->action()); } }
执行:
模块,控制器,操作都可以重新设置:
重新设置操作:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function test() { return "我是test()方法"; } public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); //参数为空,获取所有的post请求变量 $request->action("test"); dump($request->action()); } }
执行:
10.method()查看请求类型
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); dump($request->method()); } }
执行:
11.查看请求的ip
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); dump($request->ip()); } }
执行:
12.only()请求对象只获取id
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); dump($request->only('id')); } }
执行
13.except()查看除了id之外的请求变量
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); dump($request->except("id")); } }
执行:
复制惯例配置文件中的代码:
<?php return [ // URL参数方式 0 按名称成对解析 1 按顺序解析 'url_param_type' => 1, ];
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; //先继承基类 class Index extends \think\Controller { public function demo($id="",$name="",$age=18) { //调用请求类获取请求对象 $request=\think\Request::instance(); dump($request->param()); } }
url通过顺序解析
次倒伙庇芦妒兴部杠善郴档诧