thinkphp Single Letter function (shortcut method) Use Summary _php instance

Source: Internet
Author: User
Tags exception handling memory usage mixed php template throw exception vars smarty template

In thinkphp, there are many easy to use single letter function (that is, shortcut method), can be very convenient for developers to call quickly, but the letter function is not convenient memory, this article will all the letter function summed up, to facilitate the search later.

1.U () URL assembly supports different URL patterns

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

@param string $url URL expression, format: ' Module/controller/Action # anchor @ domain name]? parameter 1= value 1& parameter 2= value 2 ... '
@param string|array $vars incoming arguments, supports arrays and strings
@param string $suffix pseudo static suffix, the default is true to get configuration values
@param boolean $domain whether the domain name is displayed
@return string

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

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

@param string $name Resource Address
@param string $layer model layer Name
@return Model

The 3.M () M function is used to instantiate a model without a modeling file

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

@param string $name model name supports specifying the underlying model such as Mongomodel:user
@param string $tablePrefix Table prefix
@param mixed $connection Database connection information
@return Model

4.I () get input parameter support filter and default value

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

How to use:

 I (' id ', 0); Gets the ID parameter to automatically determine the GET or post
 I (' post.name ', ', ' htmlspecialchars ');//Get $_post[' name
 ' I (' getting. ');//Get $_get

5.B () Perform an action

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

@param string $name behavior name
@param string $tag Label name (behavior class does not need to be passed in)
@param Mixed $params parameters passed in
@return void

6.C () Read and set configuration parameters

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

@param string|array $name Configuration variables
@param mixed $value configuration value
@param mixed $default Default value
@return Mixed

7.E () throw exception handling

E ($msg, $code =0)

@param string $MSG Exception message
@param integer $code exception code defaults to 0
@return void

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

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

How to use:

 G (' begin '); Record start tag bit
 //... The interval runs code
 g (' end ');/////////////////////////////////////////////////
 Statistical interval Memory Usage

If the end marker bit is not defined, it is automatically marked with the current as a bit
Where statistical memory usage requires the MEMORY_LIMIT_ON constant to be true to be valid
@param string $start start label
@param string $end end tag
@param integer|string $dec decimal places or M
@return Mixed

9.L () Get and set language definitions (case-insensitive)

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

@param string|array $name Language variables
@param mixed $value language value or variable
@return Mixed

10.T () Get template file Format resource://Module @ Theme/controller/action

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

@param string $name template resource Address
@param string $layer view layer (directory) name
@return string

11.N () Set up and get statistical data

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

How to use:

 N (' db ', 1); Record database Operations
 N (' read ', 1);//record number of reads
 echo n (' db ');//Get all operands of the current page database
 echo n (' read ');//Get current page read count

@param string $key Identity location
@param integer $step Step value
@return Mixed

12.A () A function to instantiate the controller

Format: [Resource://][module/] Controller

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

@param string $name Resource Address
@param string $layer Control layer Name
@param integer $level Controller hierarchy
@return Controller|false

13.R () Operation method of Remote Call controller

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

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

@param string $url Call Address
@param string|array $vars Call parameters support string and array
@param string $layer The name of the control layer to invoke
@return Mixed

14.W () Render Output widget

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

@param string $name widget name
Parameters passed in @param array $data
@return void

15.S () Cache management

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

@param mixed $name Cache name, if the array represents caching settings
@param mixed $value Cache value
@param mixed $options Cache parameters
@return Mixed

16.F () Fast file data read and save for simple type data strings, arrays

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

@param string $name Cache name
@param mixed $value Cache value
@param string $path Cache path
@return Mixed

For the detailed operation of these shortcuts, readers can refer to the relevant example tutorials on this site.

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.