Think PHP shortcut functions

Source: Internet
Author: User
Tags throw exception vars

There are many easy-to-use single-letter functions (i.e., quick methods) in thinkphp, which makes it easy for developers to call quickly, but the letter function is not easy to remember, this article summarizes all the letter functions to facilitate later search.

1.U () URL assembly supports different URL patterns

?
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 parameters passed in, supporting arrays and strings
@param string $suffix pseudo-static suffix, which by default is true to get the configuration value
@param boolean $domain whether the domain name is displayed
@return string

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

?
1 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

?
1 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 parameters support filtering and default values

?
1 I($name,$default=‘‘,$filter=null)

How to use:

?
123 I(‘id‘,0); //获取id参数 自动判断get或者postI(‘post.name‘,‘‘,‘htmlspecialchars‘); //获取$_POST[‘name‘]I(‘get.‘); //获取$_GET

5.B () Perform a behavior

?
1 B($name,$tag=‘‘,&$params=NULL)

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

6.C () Read and set configuration parameters

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

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

7.E () throw exception handling

?
1 E($msg, $code=0)

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

8.G () Recording and statistics time (microseconds) and memory usage

?
1 G($start,$end=‘‘,$dec=4)

How to use:

?
12345 g ( ' begin ' ); //record start tag bit //... Interval Run code g ( //record end tag bit echo g ( ' begin ' ' end ' ,6); //statistic interval run time is accurate to decimal 6 bits echo g ( ' begin ' ' end ' ' m ' ); //statistics interval memory usage

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

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

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

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

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

?
1 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

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

How to use:

?
1234 N(‘db‘,1); // 记录数据库操作次数N(‘read‘,1); // 记录读取次数echoN(‘db‘); // 获取当前页面数据库的所有操作次数echoN(‘read‘); // 获取当前页面读取次数

@param string $key Identify the location
@param integer $step Stepping value
@return Mixed

12.A () A function for instantiating A 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 hierarchy
@return Controller|false

13.R () How to remotely invoke a controller

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 $layer The name of the control layer to invoke
@return Mixed

14.W () Render Output widget

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

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

15.S () Cache management

?
1 S($name,$value=‘‘,$options=null)

@param mixed $name Cache name if the array represents cache settings
@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

?
1 F($name, $value=‘‘,$path=DATA_PATH)

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

Think PHP shortcut functions

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.