How to get GET and POST request parameters in ThinkPHP
ThinkPHP is an open source PHP development framework that provides a simple, fast and efficient solution for web application development. In this framework, it is common to use GET and POST requests to pass parameters. This article will introduce how to obtain GET and POST request parameters in the ThinkPHP framework.
- Get GET request parameters
In ThinkPHP, use the input() function to get the parameters of the GET request. The first parameter of the input() function is the parameter name, and the second parameter is the default value. If the first parameter is not passed, all GET request parameters are obtained by default.
The sample code is as follows:
use think\facade\Request; // 获取所有GET请求参数 $getParams = Request::param(); // 获取指定参数名称的GET请求参数 $getParam = Request::param('name'); // 获取指定参数名称的GET请求参数,如果没有则使用默认值 $getParamDefault = Request::param('name', 'default value');
- Getting POST request parameters
The way to get POST request parameters is similar to getting GET request parameters. You can also use input ()function. The difference is that you need to determine whether the current request is a POST request before obtaining the parameters.
The sample code is as follows:
use think\facade\Request; // 判断当前请求是否为POST请求 if(Request::isPost()){ // 获取所有POST请求参数 $postParams = Request::param(); // 获取指定参数名称的POST请求参数 $postParam = Request::param('name'); // 获取指定参数名称的POST请求参数,如果没有则使用默认值 $postParamDefault = Request::param('name', 'default value'); }
In addition to using the input() function, you can also use the request() function to obtain GET and POST request parameters. The request() function supports both GET and POST requests, and can obtain other types of request parameters, such as Cookie, Session, server variables, etc.
The sample code is as follows:
use think\facade\Request; // 获取所有GET和POST请求参数 $params = Request::request(); // 获取指定参数名称的GET和POST请求参数 $param = Request::request('name'); // 获取指定参数名称的GET和POST请求参数,如果没有则使用默认值 $paramDefault = Request::request('name', 'default value');
Summary
Through the introduction of this article, we can learn how to obtain GET and POST request parameters in the ThinkPHP framework. Whether using the input() function or the request() function, you can easily get the request parameters. Developers can choose the appropriate method to obtain parameters according to their own needs.
The above is the detailed content of How to get GET and POST request parameters in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

