ThinkPHP单字母函数(快捷方法)使用总结_PHP
在ThinkPHP中有许多使用简便的单字母函数(即快捷方法),可以很方便开发者快速的调用,但是字母函数却不方便记忆,本文将所有的字母函数总结一下,以方便以后查找。
1.U() URL组装 支持不同URL模式
U($url='',$vars='',$suffix=true,$domain=false)
@param string $url URL表达式,格式:'[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...'
@param string|array $vars 传入的参数,支持数组和字符串
@param string $suffix 伪静态后缀,默认为true表示获取配置值
@param boolean $domain 是否显示域名
@return string
2.D() D函数用于实例化模型类 格式 [资源://][模块/]模型
D($name='',$layer='')
@param string $name 资源地址
@param string $layer 模型层名称
@return Model
3.M() M函数用于实例化一个没有模型文件的Model
M($name='',$tablePrefix='',$connection='')
@param string $name Model名称 支持指定基础模型 例如MongoModel:User
@param string $tablePrefix 表前缀
@param mixed $connection 数据库连接信息
@return Model
4.I() 获取输入参数 支持过滤和默认值
I($name,$default='',$filter=null)
使用方法:
I('id',0); //获取id参数 自动判断get或者post I('post.name','','htmlspecialchars'); //获取$_POST['name'] I('get.'); //获取$_GET
5.B() 执行某个行为
B($name,$tag='',&$params=NULL)
@param string $name 行为名称
@param string $tag 标签名称(行为类无需传入)
@param Mixed $params 传入的参数
@return void
6.C() 读取及设置配置参数
C($name=null,$value=null,$default=null)
@param string|array $name 配置变量
@param mixed $value 配置值
@param mixed $default 默认值
@return mixed
7.E() 抛出异常处理
E($msg, $code=0)
@param string $msg 异常消息
@param integer $code 异常代码 默认为0
@return void
8.G() 记录和统计时间(微秒)和内存使用情况
G($start,$end='',$dec=4)
使用方法:
G('begin'); // 记录开始标记位 // ... 区间运行代码 G('end'); // 记录结束标签位 echo G('begin','end',6); //统计区间运行时间 精确到小数后6位 echo G('begin','end','m'); // 统计区间内存使用情况
如果end标记位没有定义,则会自动以当前作为标记位
其中统计内存使用需要 MEMORY_LIMIT_ON 常量为true才有效
@param string $start 开始标签
@param string $end 结束标签
@param integer|string $dec 小数位或者m
@return mixed
9.L()获取和设置语言定义(不区分大小写)
L($name=null,$value=null)
@param string|array $name 语言变量
@param mixed $value 语言值或者变量
@return mixed
10.T()获取模版文件 格式 资源://模块@主题/控制器/操作
T($template='',$layer='')
@param string $name 模版资源地址
@param string $layer 视图层(目录)名称
@return string
11.N() 设置和获取统计数据
N($key,$step=0,$save=false)
使用方法:
N('db',1); // 记录数据库操作次数 N('read',1); // 记录读取次数 echo N('db'); // 获取当前页面数据库的所有操作次数 echo N('read'); // 获取当前页面读取次数
@param string $key 标识位置
@param integer $step 步进值
@return mixed
12.A()A函数用于实例化控制器
格式:[资源://][模块/]控制器
A($name,$layer='',$level='')
@param string $name 资源地址
@param string $layer 控制层名称
@param integer $level 控制器层次
@return Controller|false
13.R() 远程调用控制器的操作方法
URL 参数格式 [资源://][模块/]控制器/操作
R($url,$vars=array(),$layer='')
@param string $url 调用地址
@param string|array $vars 调用参数 支持字符串和数组
@param string $layer 要调用的控制层名称
@return mixed
14.W()渲染输出Widget
W($name,$data=array())
@param string $name Widget名称
@param array $data 传入的参数
@return void
15.S()缓存管理
S($name,$value='',$options=null)
@param mixed $name 缓存名称,如果为数组表示进行缓存设置
@param mixed $value 缓存值
@param mixed $options 缓存参数
@return mixed
16.F() 快速文件数据读取和保存 针对简单类型数据 字符串、数组
F($name, $value='',$path=DATA_PATH)
@param string $name 缓存名称
@param mixed $value 缓存值
@param string $path 缓存路径
@return mixed
关于这些快捷方法的详细操作,读者可以参考本站上的相关实例教程。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

RPC service based on ThinkPHP6 and Swoole implements file transfer function Introduction: With the development of the Internet, file transfer has become more and more important in our daily work. In order to improve the efficiency and security of file transfer, this article will introduce the specific implementation method of the RPC service based on ThinkPHP6 and Swoole to implement the file transfer function. We will use ThinkPHP6 as the web framework and utilize Swoole's RPC function to achieve cross-server file transfer. 1. Environmental standard
