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.
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');
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.
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');
Similarly, if you don’t want to use the default value, you can not pass the second parameter.
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');
Among them, file refers to the file type, followed by the name of the uploaded file.
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');
or
$status = input('delete.status');
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');
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!