In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to use method I in thinkphp. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
In thinkphp, the name of the I method comes from "Input", which is used to obtain system input variables more safely and conveniently, and the syntax is "I ('variable type. Variable name", [' default'], ['filter method']) "; where the variable type is not case-sensitive, while the variable name is strictly case-sensitive.
This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.
How to use method I in thinkphp
ThinkPHP's I method is a new member of many single-letter functions. Its name comes from the English Input (input). It is mainly used to obtain system input variables more easily and safely, and can be used anywhere. The usage format is as follows:
I ('variable type. Variable name', ['default'], ['filter method']) variable type refers to the request method or input type.
The meaning of each variable type is as follows: variable type meaning
Get gets GET parameters
Post gets POST parameters
Param automatically determines the request type to obtain GET, POST or PUT parameters
Request gets REQUEST parameters
Put gets PUT parameters
Session gets the $_ SESSION parameter
Cookie gets the $_ COOKIE parameter
Server gets the $_ SERVER parameter
Globals gets the $GLOBALS parameter
Note: variable types are not case sensitive.
Variable names are strictly case-sensitive.
Default values and filtering methods are optional parameters.
1. Usage:
Let's take the GET variable type as an example to illustrate the use of the following method I:
Echo I ('get.id'); / / equivalent to $_ GET [' id'] echo I ('get.name'); / / equivalent to $_ GET [' name']
Default values are supported:
Echo I ('get.id',0); / / return 0echo I (' get.name','') if $_ GET ['id'] does not exist; / / return empty string if $_ GET [' name'] does not exist
Use the method to filter:
Echo I ('get.name','','htmlspecialchars'); / / filter $_ GET [' name'] using the htmlspecialchars method, and return an empty string if it does not exist
Support getting the entire variable type directly, for example:
I ('get.'); / / get the entire $_ GET array
In the same way, we can get variables of post or other input types, such as:
I ('post.name','','htmlspecialchars'); / filter $_ POST [' name'] using the htmlspecialchars method, and return the empty string I ('session.user_id',0) if it doesn't exist; / / get $_ SESSION [' user_id'] if it doesn't exist, default to 0I ('cookie.'); / / get the entire $_ COOKIE array I (' server.REQUEST_METHOD') / / get $_ SERVER ['REQUEST_METHOD']
Param variable type is a framework-specific variable acquisition method that supports automatic determination of the current request type, such as:
Echo I ('param.id')
If the current request type is GET, it is equivalent to $_ GET ['id'], and if the current request type is POST or PUT, it is equivalent to getting $_ POST [' id'] or the PUT parameter id.
And param type variables can also get URL parameters by numerical index (must be valid for PATHINFO mode parameters, whether GET or POST), for example:
The current access URL address is
Http://serverName/index.php/New/2013/06/01
Then we can pass
Echo I ('param.1'); / / output 2013echo I (' param.2'); / / output 06echo I ('param.3'); / / output 01
In fact, the writing of param variable types can be simplified to:
I ('id'); / / equivalent to I (' param.id') I ('name'); / / equivalent to I (' param.name') above is all the content of this article "how to use I method in thinkphp". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.