豪柏大厦做网站的公司,金乡做网站,门户网站建设的公司,中国优秀的企业网站一、Request对象
thinkphp提供了Request对象#xff0c;其可以 支持对全局输入变量的检测、获取和安全过滤 支持获取包括$_GET、$_POST、$_REQUEST、$_SERVER、$_SESSION、$_COOKIE、$_ENV等系统变量#xff0c;以及文件上传信息 具体参考#xff1a;https://www.kanclou…一、Request对象
thinkphp提供了Request对象其可以 支持对全局输入变量的检测、获取和安全过滤 支持获取包括$_GET、$_POST、$_REQUEST、$_SERVER、$_SESSION、$_COOKIE、$_ENV等系统变量以及文件上传信息 具体参考https://www.kancloud.cn/manual/thinkphp6_0/1037519 二、可以通过Request::param获取所有输入参数
PARAM类型变量是框架提供的用于自动识别当前请求的一种变量获取方式是系统推荐的获取请求参数的方法。 新建一个html页面
app/test/view/User/loginsimple.html
!DOCTYPE htmlhtml langenhead/headbody form methodpost action/index.php/test/User/dologin?logintype2 input typetext nameusernamebr input typetext namepasswordbr input typesubmit value提交 /form /body
/html 注意提交路径为/index.php/test/User/dologin/func/login?logintype2 2. 新建一个控制器函数
app\test\Controller\User.php
引入
use think\facade\Request;
函数
?phpnamespace app\test\controller;
use app\BaseController;// 添加引用use think\facade\View;use think\facade\Request;
class User extends BaseController{ // 登录页 public function loginsimple(){ // 模板输出 return View::fetch(User/loginsimple); }// 登录 public function dologin(){ // 静态调用 // 获取当前请求get中的logintype变量 print_r(Request::param(logintype)); print_r(br/); // 获取当前请求get中的路径参数func变量 print_r(Request::param(func)); print_r(br/); // 获取当前请求post中的name变量 print_r(Request::param(username)); print_r(br/); // 获取当前请求的所有变量经过过滤 print_r(Request::param()); print_r(br/); // 获取当前请求未经过滤的所有变量 print_r(Request::param(false)); print_r(br/); // 获取部分变量 print_r(Request::param([username, email])); }
}3. 测试 点击提交之后 可以看到Request::param成功提取到了get中参数、url中的路径参数、post中的参数