ThinkPHP/Commonfunctions.php

Think 标准模式公共函数库

Functions

halt()

halt(mixed  $error) : void

错误输出

Parameters

mixed $error

错误

throw_exception()

throw_exception(string  $msg, string  $type = 'ThinkException', integer  $code) : void

自定义异常处理

Parameters

string $msg

异常消息

string $type

异常类型 默认为ThinkException

integer $code

异常代码 默认为0

dump()

dump(mixed  $var, boolean  $echo = true, string  $label = null, boolean  $strict = true) : void|string

浏览器友好的变量输出

Parameters

mixed $var

变量

boolean $echo

是否输出 默认为True 如果为false 则返回输出字符串

string $label

标签 默认为空

boolean $strict

是否严谨 默认为true

Returns

void|string

_404()

_404(string  $msg = '', string  $url = '') : void

404处理 调试模式会抛异常 部署模式下面传入url参数可以指定跳转页面,否则发送404信息

Parameters

string $msg

提示信息

string $url

跳转URL地址

layout()

layout(string|false  $layout) : void

设置当前页面的布局

Parameters

string|false $layout

布局名称 为false的时候表示关闭布局

U()

U(string  $url = '', string|array  $vars = '', string  $suffix = true, boolean  $redirect = false, boolean  $domain = false) : string

URL组装 支持不同URL模式

Parameters

string $url

URL表达式,格式:'[分组/模块/操作#锚点@域名]?参数1=值1&参数2=值2...'

string|array $vars

传入的参数,支持数组和字符串

string $suffix

伪静态后缀,默认为true表示获取配置值

boolean $redirect

是否跳转,如果设置为true则表示跳转到该URL地址

boolean $domain

是否显示域名

Returns

string

W()

W(string  $name, array  $data = array(), boolean  $return = false, string  $path = '') : void

渲染输出Widget

Parameters

string $name

Widget名称

array $data

传入的参数

boolean $return

是否返回内容

string $path

Widget所在路径

filter()

filter(string  $name, string  $content) : void

过滤器方法 引用传值

Parameters

string $name

过滤器名称

string $content

要过滤的内容

is_ssl()

is_ssl() : boolean

判断是否SSL协议

Returns

boolean

redirect()

redirect(string  $url, integer  $time, string  $msg = '') : void

URL重定向

Parameters

string $url

重定向的URL地址

integer $time

重定向的等待时间(秒)

string $msg

重定向前的提示信息

S()

S(mixed  $name, mixed  $value = '', mixed  $options = null) : mixed

缓存管理

Parameters

mixed $name

缓存名称,如果为数组表示进行缓存设置

mixed $value

缓存值

mixed $options

缓存参数

Returns

mixed

cache()

cache(  $name,   $value = '',   $options = null) 

Parameters

$name
$value
$options

F()

F(string  $name, mixed  $value = '', string  $path = DATA_PATH) : mixed

快速文件数据读取和保存 针对简单类型数据 字符串、数组

Parameters

string $name

缓存名称

mixed $value

缓存值

string $path

缓存路径

Returns

mixed

get_instance_of()

get_instance_of(string  $name, string  $method = '', array  $args = array()) : object

取得对象实例 支持调用类的静态方法

Parameters

string $name

类名

string $method

方法名,如果为空则返回实例化对象

array $args

调用参数

Returns

object

to_guid_string()

to_guid_string(mixed  $mix) : string

根据PHP各种类型变量生成唯一标识号

Parameters

mixed $mix

变量

Returns

string

xml_encode()

xml_encode(mixed  $data, string  $root = 'think', string  $item = 'item', string  $attr = '', string  $id = 'id', string  $encoding = 'utf-8') : string

XML编码

Parameters

mixed $data

数据

string $root

根节点名

string $item

数字索引的子节点名

string $attr

根节点属性

string $id

数字索引子节点key转换的属性名

string $encoding

数据编码

Returns

string

data_to_xml()

data_to_xml(mixed  $data, string  $item = 'item', string  $id = 'id') : string

数据XML编码

Parameters

mixed $data

数据

string $item

数字索引时的节点名称

string $id

数字索引key转换为的属性名

Returns

string

session()

session(string|array  $name, mixed  $value = '') : mixed

session管理函数

Parameters

string|array $name

session名称 如果为数组则表示进行session设置

mixed $value

session值

Returns

mixed

cookie()

cookie(string  $name, mixed  $value = '',   $option = null) : mixed

Cookie 设置、获取、删除

Parameters

string $name

cookie名称

mixed $value

cookie值

$option

Returns

mixed

load_ext_file()

load_ext_file() : void

加载动态扩展文件

get_client_ip()

get_client_ip(integer  $type) : mixed

获取客户端IP地址

Parameters

integer $type

返回类型 0 返回IP地址 1 返回IPV4地址数字

Returns

mixed

send_http_status()

send_http_status(integer  $code) : void

发送HTTP状态

Parameters

integer $code

状态码

think_filter()

think_filter(  $value) 

Parameters

$value