1. Request
Object
thinkphp provides Request
objects, which can
-
Support detection, acquisition and security filtering of global input variables
-
Supports obtaining system variables including
$_GET
,$_POST
,$_REQUEST
,$_SERVER
,$_SESSION
,$_COOKIE
, and file upload information$_ENV
Specific reference: https://www.kancloud.cn/manual/thinkphp6_0/1037519
2. All input parameters can be obtained through Request::param
PARAM
Type variable is a variable acquisition method provided by the framework to automatically identify the current request, and is the method recommended by the system to obtain request parameters.
-
Create a new html page
app/test/view/User/loginsimple.html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form method="post" action="/index.php/test/User/dologin?logintype=2" >
<input type="text" name="username"><br>
<input type="text" name="password"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
Note: The submission path is /index.php/test/User/dologin/func/login?logintype=2
2. Create a new controller function
app\test\Controller\User.php
introduce
use think\facade\Request;
function
<?php
namespace 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. Test
After clicking submit
It can be seen that Request::param has successfully extracted the parameters in get, the path parameters in url, and the parameters in post