Home > PHP Framework > ThinkPHP > body text

Detailed introduction to how thinkphp accepts page data

PHPz
Release: 2023-04-14 13:40:38
Original
656 people have browsed it

With the rapid development of the Internet, there are more and more websites, and our lives are becoming more and more dependent on it. In the website development process, how to accept page data is a very important step. This article will introduce in detail how thinkphp accepts page data.

  1. Accept parameters passed by GET method

Passing parameters by GET method is the most common transmission method, such as: http://www.example.com/index .php?name=thinkphp&age=3. In thinkphp, accepting parameters passed through GET is very simple, just use the input() method.

For example, we accept a parameter named name:

$name = input('get.name');
Copy after login

Among them, the input() method has two parameters, the first is the parameter name, and the second is the default value. Of course, if you don't want to use the default value, you can not pass the second parameter.

  1. Accept parameters passed by POST method

Passing parameters by POST method is another common transmission method. Accepting parameters passed by POST is also very simple, also using the input() method.

For example, we accept a parameter named username:

$username = input('post.username');
Copy after login

Similarly, if you don’t want to use the default value, you can not pass the second parameter.

  1. Accept uploaded files

In website development, uploading files is also a common operation. In thinkphp, accepting uploaded files is also very simple. We can use the input() method to accept uploaded files.

For example, we accept an uploaded file named image:

$image = input('file.image');
Copy after login

Among them, file refers to the file type, followed by the name of the uploaded file.

  1. Accept parameters passed by PUT and DELETE methods

PUT and DELETE passed parameters are not specified in the traditional HTTP protocol, but they are very common in RESTful APIs a method of transmission. In thinkphp, parameters passed by PUT and DELETE can also be easily accepted.

For example, we accept a parameter called status:

$status = input('put.status');
Copy after login

or

$status = input('delete.status');
Copy after login
  1. Accept path parameters

in routing , sometimes it is necessary to accept path parameters. For example, we need to access a link: http://www.example.com/index.php/User/123, where "123" is the path parameter. In thinkphp, we can use the input() method to accept path parameters.

For example, we accept a path parameter named id:

$id = input('param.id');
Copy after login

Similarly, if you don’t want to use the default value, you can not pass the second parameter.

Summary

This article mainly introduces the five ways thinkphp accepts page data, including parameters passed by GET and POST methods, uploaded files, parameters passed by PUT and DELETE methods, and path parameters. These methods are very simple and easy to understand, whether you are a beginner or an experienced developer, you can easily get started. Hope this article can be helpful to you.

The above is the detailed content of Detailed introduction to how thinkphp accepts page data. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template