load_trait() load_trait(string $class, string $ext = EXT) : bool 快速导入Traits PHP5.5以上无需调用 Parameters string $class trait库 string $ext 类库后缀 Returns bool —
exception() exception(string $msg, int $code, string $exception = '') : mixed 抛出异常处理 Parameters string $msg 异常消息 int $code 异常代码 默认为0 string $exception 异常类 Throws \Exception Returns mixed —
debug() debug(string $start, string $end = '', int|string $dec = 6) : mixed 记录时间(微秒)和内存使用情况 Parameters string $start 开始标签 string $end 结束标签 int|string $dec 小数位 如果是m 表示统计内存占用 Returns mixed —
lang() lang(string $name, array $vars = [], string $lang = '') : mixed 获取语言变量值 Parameters string $name 语言变量名 array $vars 动态变量值 string $lang 语言 Returns mixed —
config() config(string|array $name = '', mixed $value = null, string $range = '') : mixed 获取和设置配置参数 Parameters string|array $name 参数名 mixed $value 参数值 string $range 作用域 Returns mixed —
input() input(string $key = '', mixed $default = null, string $filter = '') : mixed 获取输入数据 支持默认值和过滤 Parameters string $key 获取的变量名 mixed $default 默认值 string $filter 过滤方法 Returns mixed —
widget() widget(string $name, array $data = []) : mixed 渲染输出Widget Parameters string $name Widget名称 array $data 传入的参数 Returns mixed —
model() model(string $name = '', string $layer = 'model', bool $appendSuffix = false) : \think\Model 实例化Model Parameters string $name Model名称 string $layer 业务层名称 bool $appendSuffix 是否添加类名后缀 Returns \think\Model —
validate() validate(string $name = '', string $layer = 'validate', bool $appendSuffix = false) : \think\Validate 实例化验证器 Parameters string $name 验证器名称 string $layer 业务层名称 bool $appendSuffix 是否添加类名后缀 Returns \think\Validate —
db() db(string $name = '', array|string $config = [], bool $force = false) : \think\db\Query 实例化数据库类 Parameters string $name 操作的数据表名称(不含前缀) array|string $config 数据库配置参数 bool $force 是否强制重新连接 Returns \think\db\Query —
controller() controller(string $name, string $layer = 'controller', bool $appendSuffix = false) : \think\Controller 实例化控制器 格式:[模块/]控制器 Parameters string $name 资源地址 string $layer 控制层名称 bool $appendSuffix 是否添加类名后缀 Returns \think\Controller —
action() action(string $url, string|array $vars = [], string $layer = 'controller', bool $appendSuffix = false) : mixed 调用模块的操作方法 参数格式 [模块/控制器/]操作 Parameters string $url 调用地址 string|array $vars 调用参数 支持字符串和数组 string $layer 要调用的控制层名称 bool $appendSuffix 是否添加类名后缀 Returns mixed —
import() import(string $class, string $baseUrl = '', string $ext = EXT) : bool 导入所需的类库 同java的Import 本函数有缓存功能 Parameters string $class 类库命名空间字符串 string $baseUrl 起始路径 string $ext 导入的文件扩展名 Returns bool —
vendor() vendor(string $class, string $ext = EXT) : bool 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面 Parameters string $class 类库 string $ext 类库后缀 Returns bool —
dump() dump(mixed $var, bool $echo = true, string $label = null) : void|string 浏览器友好的变量输出 Parameters mixed $var 变量 bool $echo 是否输出 默认为true 如果为false 则返回输出字符串 string $label 标签 默认为空 Returns void|string —
url() url(string $url = '', string|array $vars = '', bool|string $suffix = true, bool|string $domain = false) : string Url生成 Parameters string $url 路由地址 string|array $vars 变量 bool|string $suffix 生成的URL后缀 bool|string $domain 域名 Returns string —
session() session(string|array $name, mixed $value = '', string $prefix = null) : mixed Session管理 Parameters string|array $name session名称,如果为数组表示进行session设置 mixed $value session值 string $prefix 前缀 Returns mixed —
cookie() cookie(string|array $name, mixed $value = '', mixed $option = null) : mixed Cookie管理 Parameters string|array $name cookie名称,如果为数组表示进行cookie设置 mixed $value cookie值 mixed $option 参数 Returns mixed —
cache() cache(mixed $name, mixed $value = '', mixed $options = null, string $tag = null) : mixed 缓存管理 Parameters mixed $name 缓存名称,如果为数组表示进行缓存设置 mixed $value 缓存值 mixed $options 缓存参数 string $tag 缓存标签 Returns mixed —
trace() trace(mixed $log = '[think]', string $level = 'log') : void|array 记录日志信息 Parameters mixed $log log信息 支持字符串和数组 string $level 日志级别 Returns void|array —
response() response(mixed $data = [], int|string $code = 200, array $header = [], string $type = 'html') : \Response 创建普通 Response 对象实例 Parameters mixed $data 输出数据 int|string $code 状态码 array $header 头信息 string $type Returns \Response —
view() view(string $template = '', array $vars = [], array $replace = [], int $code = 200) : \think\response\View 渲染模板输出 Parameters string $template 模板文件 array $vars 模板变量 array $replace 模板替换 int $code 状态码 Returns \think\response\View —
json() json(mixed $data = [], int $code = 200, array $header = [], array $options = []) : \think\response\Json 获取\think\response\Json对象实例 Parameters mixed $data 返回的数据 int $code 状态码 array $header 头部 array $options 参数 Returns \think\response\Json —
jsonp() jsonp(mixed $data = [], int $code = 200, array $header = [], array $options = []) : \think\response\Jsonp 获取\think\response\Jsonp对象实例 Parameters mixed $data 返回的数据 int $code 状态码 array $header 头部 array $options 参数 Returns \think\response\Jsonp —
xml() xml(mixed $data = [], int $code = 200, array $header = [], array $options = []) : \think\response\Xml 获取\think\response\Xml对象实例 Parameters mixed $data 返回的数据 int $code 状态码 array $header 头部 array $options 参数 Returns \think\response\Xml —
redirect() redirect(mixed $url = [], array|int $params = [], int $code = 302, array $with = []) : \think\response\Redirect 获取\think\response\Redirect对象实例 Parameters mixed $url 重定向地址 支持Url::build方法的地址 array|int $params 额外参数 int $code 状态码 array $with 隐式传参 Returns \think\response\Redirect —
abort() abort(int|\Response $code, string $message = null, array $header = []) : mixed 抛出HTTP异常 Parameters int|\Response $code 状态码 或者 Response对象实例 string $message 错误信息 array $header 参数 Returns mixed —
token() token(string $name = '__token__', mixed $type = 'md5') : string 生成表单令牌 Parameters string $name 令牌名称 mixed $type 令牌生成方法 Returns string —
load_relation() load_relation(mixed $resultSet, mixed $relation) : array 延迟预载入关联查询 Parameters mixed $resultSet 数据集 mixed $relation 关联 Returns array —
collection() collection(array $resultSet) : \think\model\Collection|\think\Collection 数组转换为数据集对象 Parameters array $resultSet 数据集数组 Returns \think\model\Collection|\think\Collection —