Summary of the use of ThinkPHP single letter function of shortcut method

  • 2021-07-09 07:38:24
  • OfStack

In ThinkPHP, there are many simple single letter functions (that is, shortcut methods), which can be very convenient for developers to call quickly, but letter functions are inconvenient to remember. This paper summarizes all letter functions under 1 to facilitate future search.

1. U () URL assembly supports different URL modes


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

@ param string $url URL expression in the format '[Module/Controller/Action # Anchor @ Domain Name]? Parameter 1 = Value 1 & Parameter 2 = value 2... '
@ param stringarray $vars passed in parameters that support arrays and strings
@ param string $suffix pseudo static suffix, default to true means to get configuration value
@ param boolean $domain Do you display domain names
@return string

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


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 an Model without a model file


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

The @ param string $name Model name supports specifying the underlying model for example MongoModel: User
@ param string $tablePrefix table prefix
@ param mixed $connection database connection information
@return Model

4. I () gets input parameter support filtering and default values


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

Usage:


 I('id',0); // Get id Parameter   Automatic judgment get Or post
 I('post.name','','htmlspecialchars'); // Get $_POST['name']
 I('get.'); // Get $_GET

5. B () performs a behavior


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

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

6. C () reads and sets configuration parameters


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

@ param stringarray $name configuration variable
@ param mixed $value configuration value
@ param mixed $default Default
@return mixed

7. E () throws exception handling


E($msg, $code=0)

@ param string $msg Exception Message
@ param integer $code exception code defaults to 0
@return void

8. G () records and counts time (microseconds) and memory usage


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

Usage:


 G('begin'); //  Record start flag bit 
 // ...  Interval operation code 
 G('end'); //  End of record tag bit 
 echo G('begin','end',6); // Statistical interval running time   Accurate to the decimal 6 Bit 
 echo G('begin','end','m'); //  Statistics interval memory usage 

If the end flag bit is not defined, the current is automatically used as the flag bit
Where statistical memory usage requires the MEMORY_LIMIT_ON constant to be true to be valid
@ param string $start Start Tag
@ param string $end end tag
@ param integerstring $dec decimal or m
@return mixed

9. L () Gets and sets the language definition (case-insensitive)


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

@ param stringarray $name language variable
@ param mixed $value language value or variable
@return mixed

10. T () Get Template File Format Resources://Module @ Subject/Controller/Action


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

@ param string $name Template Resource Address
@ param string $layer View Layer (Directory) Name
@return string

11. N () Setting up and getting statistics


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

Usage:


 N('db',1); //  Record the number of database operations 
 N('read',1); //  Record the number of reads 
 echo N('db'); //  Gets the number of all operations of the current page database 
 echo N('read'); //  Gets the number of current page reads 

@ param string $key Identity Location
@ param integer $step Step Value
@return mixed

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

Format: [Resource://] [Module/] Controller


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

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

13. Operation method of R () remote call controller

URL Parameter Format [Resource://] [Module/] Controller/Action


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

@ param string $url Call Address
@ param stringarray $vars call parameter supports strings and arrays
@ param string $layer the name of the control layer to call
@return mixed

14. W () rendering output Widget


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

@ param string $name Widget Name
@ param array $data incoming parameters
@return void

15. S () cache management


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

@ param mixed $name cache name, if cached for array representation
@ param mixed $value cache value
@ param mixed $options cache parameters
@return mixed

16. F () fast file data reading and saving 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.

Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "smarty Template Introduction Basic Tutorial" and "PHP Template Technology Summary".

I hope this article is helpful to the PHP programming based on ThinkPHP framework.


Related articles: