ThinkPHP single letter function (shortcut) usage summary-favana

Source: Internet
Author: User
ThinkPHP single letter function (shortcut) usage summary-favana

This article mainly introduces the use of ThinkPHP single-letter functions (shortcuts) and summarizes ThinkPHP shortcuts. For more information, see

ThinkPHP has many easy-to-use single-letter functions (that is, quick methods), which can be easily called by developers, but the letter functions are not easy to remember. This article will summarize all the letter functions, to facilitate future search.

1. U () URL Assembly supports different URL modes

?

1

U($url='',$vars='',$suffix=true,$domain=false)

@ Param string $ url URL expression. Format: '[module/controller/Operation # anchor @ domain name]? Parameter 1 = value 1 & parameter 2 = value 2 ...'
@ Param string | array $ vars input parameters, which support arrays and strings
@ Param string $ suffix: pseudo-static suffix. the default value is true, indicating that the configuration value is obtained.
@ Param boolean $ whether the domain name is displayed
@ Return string

2. D () D function is used to instantiate the model class format [resource: //] [module/] model

?

1

D($name='',$layer='')

@ Param string $ name: resource address
@ Param string $ layer model layer name
@ Return Model

3. the M () M function is used to instantiate a Model without a Model file.

?

1

M($name='',$tablePrefix='',$connection='')

@ Param string $ name the Model name supports specifying the basic Model, for example, role Model: User
@ Param string $ tablePrefix table prefix
@ Param mixed $ connection database connection information
@ Return Model

4. I () supports filtering input parameters and default values.

?

1

I($name,$default='',$filter=null)

Usage:

?

1

2

3

I('id',0); // Get the id parameter to automatically determine get or post

I('post.name','','htmlspecialchars'); // Get $ _ POST ['name']

I('get.'); // GET $ _ GET

5. B () executes a behavior

?

1

B($name,$tag='',&$params=NULL)

@ Param string $ name behavior name
@ Param string $ tag name (the behavior class does not need to be passed in)
@ Param Mixed $ parameters passed in by params
@ Return void

6. C () read and set configuration parameters

?

1

C($name=null,$value=null,$default=null)

@ Param string | array $ name configuration variable
@ Param mixed $ value configuration value
@ Param mixed $ default value
@ Return mixed

7. E () throw exception handling

?

1

E($msg, $code=0)

@ Param string $ msg exception message
@ Param integer $ the default code for code exceptions is 0.
@ Return void

8.G () record and statistical time (microseconds) and memory usage

?

1

G($start,$end='',$dec=4)

Usage:

?

1

2

3

4

5

G('begin'); // Record start flag bit

// Run the code in the... interval

G('end'); // Record end tag bit

echo G('begin','end',6); // The running time of the statistical interval is accurate to the last six digits of the decimal number.

echo G('begin','end','m'); // Count the memory usage in the interval

If the end tag is not defined, the current tag is automatically used as the tag.
The MEMORY_LIMIT_ON constant must be set to true for memory usage statistics.
@ Param string $ start tag
@ Param string $ end tag
@ Param integer | string $ dec decimal point or m
@ Return mixed

9. L () get and set language definitions (case insensitive)

?

1

L($name=null,$value=null)

@ Param string | array $ name language variable
@ Param mixed $ value language value or variable
@ Return mixed

10. T () get template file format resources: // module @ topic/controller/operation

?

1

T($template='',$layer='')

@ Param string $ name: Template resource address
@ Param string $ layer view layer (directory) name
@ Return string

11. N () set and obtain statistics

?

1

N($key,$step=0,$save=false)

Usage:

?

1

2

3

4

N('db',1); // Record the number of database operations

N('read',1); // Record the number of reads

echo N('db'); // Obtain the number of database operations on the current page

echo N('read'); // Obtain the number of reads on the current page

@ Param string $ key ID location
@ Param integer $ step value
@ Return mixed

12. function A () A is used to instantiate the controller.

Format: [resource: //] [module/] controller

?

1

A($name,$layer='',$level='')

@ Param string $ name: resource address
@ Param string $ layer Control layer name
@ Param integer $ level controller level
@ Return Controller | false

13. R () remote call of the controller operation method

URL parameter format [resource: //] [module/] controller/operation

?

1

R($url,$vars=array(),$layer='')

@ Param string $ url call address
@ Param string | array $ vars call parameters support strings and arrays
@ Param string $ name of the control layer to be called by the layer
@ Return mixed

14. W () rendering output Widget

?

1

W($name,$data=array())

@ Param string $ name Widget name
@ Param array $ parameters passed in by data
@ Return void

15. S () cache management

?

1

S($name,$value='',$options=null)

@ Param mixed $ name indicates the cache name. if it is an array, cache settings are performed.
@ Param mixed $ value cache value
@ Param mixed $ options cache parameters
@ Return mixed

16. F () fast file data reading and storageFor simple data strings and arrays

?

1

F($name, $value='',$path=DATA_PATH)

@ Param string $ name cache name
@ Param mixed $ value cache value
@ Param string $ path: cache path
@ Return mixed

For detailed operations on these shortcuts, you can refer to the related instance tutorials on this site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.