There are many easy-to-use single-letter functions (i.e. shortcut methods) in ThinkPHP, which are easy for developers to call quickly, but alphabetical functions are not convenient to remember. This article summarizes all alphabetic functions to facilitate future 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¶meter 2=value 2...'
@param string| array $vars Incoming parameters, supports arrays and strings
@param string $suffix Pseudo-static suffix, the default is true to obtain the configuration value
@param boolean $domain Whether to display the domain name
@return string
2.D() D function is used to instantiate model class format [resource://][module/]model
?1 |
D( $name = '' , $layer = '' )
|
@param string $name resource address
@param string $layer model layer name
@return Model
3.M() The M function is used to instantiate a Model without a model file
?1 |
M( $name = '' , $tablePrefix = '' , $connection = '' )
|
@param string $name Model name supports specifying basic models such as MongoModel:User
@param string $tablePrefix table prefix
@param mixed $connection database connection information
@return Model
4.I() gets input parameters and supports filtering and default values
?1 |
I( $name , $default = '' , $filter =null)
|
How to use:
?1 2 3 |
I( 'id' ,0); //获取id参数 自动判断get或者post
I( 'post.name' , '' , 'htmlspecialchars' ); //获取$_POST['name']
I( 'get.' ); //获取$_GET
|
5.B() perform a certain behavior
?1 |
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() 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 default value
@return mixed
7.E() throws exception handling
?1 |
E( $msg , $code =0)
|
@param string $msg Exception message
@param integer $code Exception code Default is 0
@return void
8.G() records and counts time (microseconds) and memory usage
?1 |
G( $start , $end = '' , $dec =4)
|
How to use:
?1 2 3 4 5 |
G( 'begin' ); // 记录开始标记位
// ... 区间运行代码
G( 'end' ); // 记录结束标签位
echo G( 'begin' , 'end' ,6); //统计区间运行时间 精确到小数后6位
echo G( 'begin' , 'end' , 'm' ); // 统计区间内存使用情况
|
If the end mark bit is not defined, the current mark bit will be automatically used
The statistical memory usage requires MEMORY_LIMIT_ON constant to be true to be valid
@param string $start start tag
@param string $end End tag
@param integer|string $dec decimal place or m
@return mixed
9.L() gets and sets the language definition (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 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 and get statistics
?1 |
N( $key , $step =0, $save =false)
|
How to use:
?1 2 3 4 |
N( 'db' ,1); // 记录数据库操作次数
N( 'read' ,1); // 记录读取次数
echo N( 'db' ); // 获取当前页面数据库的所有操作次数
echo N( 'read' ); // 获取当前页面读取次数
|
@param string $key identification position
@param integer $step step value
@return mixed
12.A()A function 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 controller operation method
URL parameter format [resource://][module/]controller/operation
?1 |
R( $url , $vars = array (), $layer = '' )
|
@param string $url calling address
@param string|array $vars calling parameters support strings and arrays
@param string $layer name of the control layer to be called
@return mixed
14.W() render output Widget
?1 |
W( $name , $data = array ())
|
@param string $name Widget name
@param array $data Incoming parameters
@return void
15.S() Cache Management
?1 |
S( $name , $value = '' , $options =null)
|
@param mixed $name cache name, if cache setting is 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
?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 of these shortcut methods, readers can refer to the relevant example tutorials on this site.