Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the I method in thinkphp

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use method I in thinkphp". In daily operation, I believe that many people have doubts about how to use method I in thinkphp. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use method I in thinkphp". Next, please follow the editor to study!

The code of the I method in thinkphp is "I ('variable type. Variable name', ['default']], ['filter method']"; the name of the I method comes from "input", which means input, and is used to obtain system input variables more conveniently and safely.

This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.

What is the code of the I method in thinkphp

Is a new member of many single-letter functions in ThinkPHP. Its name comes from the English Input (input). It is mainly used to obtain system input variables more conveniently 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, including:

Note: variable types are not case sensitive.

Variable names are strictly case-sensitive.

Default values and filtering methods are optional parameters.

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'), the study of "how to use I method in thinkphp" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report