applicationcommon.php

Constants

ROOT_URL

ROOT_URL = \think\facade\Request::rootUrl() . '/'

TEMPLATE_PATH

TEMPLATE_PATH = \ROOT_PATH . 'templates' . \DS

Functions

cache()

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

系统缓存缓存管理 cache('model') 获取model缓存 cache('model',null) 删除model缓存

Parameters

mixed $name

缓存名称

mixed $value

缓存值

mixed $options

缓存参数

Returns

mixed —

fun()

fun(mixed  $fun) : mixed

加载其他模块函数

Parameters

mixed $fun

Returns

mixed —

cdnurl()

cdnurl(string  $url, bool  $domain = false) : string

获取上传资源的CDN的地址

Parameters

string $url

资源相对地址

bool $domain

是否显示域名 或者直接传入域名

Returns

string —

int_to_string()

int_to_string(mixed  $data, array  $map = array('status' => array(1 => '正常', -1 => '删除', 0 => '禁用', 2 => '未审核', 3 => '草稿'))) : array

select返回的数组进行整数映射转换

Parameters

mixed $data
array $map

映射关系二维数组 array( '字段名1'=>array(映射关系数组), '字段名2'=>array(映射关系数组), ...... )

Returns

array —

array( array('id'=>1,'title'=>'标题','status'=>'1','status_text'=>'正常') .... )

str2arr()

str2arr(string  $str, string  $glue = ',') : array

字符串转换为数组,主要用于把分隔符调整到第二个参数

Parameters

string $str

要分割的字符串

string $glue

分割符

Returns

array —

arr2str()

arr2str(array  $arr, string  $glue = ',') : string

数组转换为字符串,主要用于把分隔符调整到第二个参数

Parameters

array $arr

要连接的数组

string $glue

分割符

Returns

string —

str_cut()

str_cut(mixed  $sourcestr,  $length,  $dot = '...') : mixed

字符截取

Parameters

mixed $sourcestr
$length

长度

$dot

Returns

mixed —

to_time()

to_time(array  $arr, string  $field = 'time', string  $format = 'Y-m-d H:i:s') : mixed

时间转换

Parameters

array $arr

传入数组

string $field

字段名

string $format

格式

Returns

mixed —

to_ip()

to_ip(array  $arr, string  $field = 'ip') : mixed

ip转换

Parameters

array $arr

传入数组

string $field

字段名

Returns

mixed —

list_sort_by()

list_sort_by(array  $list, string  $field, array  $sortby = 'asc') : array

对查询结果集进行排序

Parameters

array $list

查询结果

string $field

排序的字段名

array $sortby

排序类型 asc正向排序 desc逆向排序 nat自然排序

Returns

array —

list_to_tree()

list_to_tree(array  $list, mixed  $pk = 'id', string  $pid = 'parentid', mixed  $child = '_child', mixed  $root) : array

把返回的数据集转换成Tree

Parameters

array $list

要转换的数据集

mixed $pk
string $pid

parent标记字段

mixed $child
mixed $root

Returns

array —

parse_attr()

parse_attr(string  $value = '') : array|string

解析配置

Parameters

string $value

配置值

Returns

array|string —

time_format()

time_format(int  $timestamp = null, mixed  $type) : string

时间戳格式化

Parameters

int $timestamp
mixed $type

Returns

string —

完整的时间显示

human_date()

human_date(int  $time, int  $local = null) : string

获取语义化时间

Parameters

int $time

时间

int $local

本地时间

Returns

string —

format_bytes()

format_bytes(\number  $size, string  $delimiter = '') : string

格式化字节大小

Parameters

\number $size

字节数

string $delimiter

数字和单位分隔符

Returns

string —

格式化后的带单位的大小

to_guid_string()

to_guid_string(mixed  $mix) : string

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

Parameters

mixed $mix

变量

Returns

string —

encrypt_password()

encrypt_password( $password,  $encrypt = '') : mixed

对用户的密码进行加密

Parameters

$password
$encrypt

//传入加密串,在修改密码时做认证

Returns

mixed —

genRandomString()

genRandomString(\type  $len = 6) : string

产生一个指定长度的随机字符串,并返回给用户

Parameters

\type $len

产生字符串的长度

Returns

string —

随机字符串

getModel()

getModel(\type  $modelid, \type  $name = '') : bool

获取模型数据

Parameters

\type $modelid

模型ID

\type $name

返回的字段,默认返回全部,数组

Returns

bool —

thumb()

thumb(\type  $imgurl, \type  $width = 100, \type  $height = 100, \type  $thumbType = 1, \type  $smallpic = 'none.png') : \type

生成缩略图

Parameters

\type $imgurl

图片地址

\type $width

缩略图宽度

\type $height

缩略图高度

\type $thumbType

缩略图生成方式

\type $smallpic

图片不存在时显示默认图片

Returns

\type —

http_down()

http_down(string  $url, string  $filename = "", int  $timeout = 60) : string

下载远程文件,默认保存在temp下

Parameters

string $url

网址

string $filename

保存文件名

int $timeout

过期时间

Returns

string —

本地文件名

safe_replace()

safe_replace( $string) : string

安全过滤函数

Parameters

$string

Returns

string —

sys_auth()

sys_auth(mixed  $string, string  $operation = 'ENCODE', string  $key = '', string  $expiry) : string

字符串加密、解密函数

Parameters

mixed $string
string $operation

ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,

string $key

密钥:数字、字母、下划线

string $expiry

过期时间

Returns

string —

hsv2rgb()

hsv2rgb(mixed  $h, mixed  $s, mixed  $v) : mixed

Parameters

mixed $h
mixed $s
mixed $v

Returns

mixed —

letter_avatar()

letter_avatar( $text) : string

首字母头像

Parameters

$text

Returns

string —

build_suffix_image()

build_suffix_image(string  $suffix, null  $background = null) : string

生成文件后缀图片

Parameters

string $suffix

后缀

null $background

Returns

string —

check_cors_request()

check_cors_request() : mixed

跨域检测

Returns

mixed —

var_export_short()

var_export_short(mixed  $data, bool  $return = true) : string

使用短标签打印或返回数组结构

Parameters

mixed $data
bool $return

是否返回数据

Returns

string —

getListOrder()

getListOrder( $catid) : mixed|string

配置列表页全局配许

Parameters

$catid

Returns

mixed|string —

getCatid()

getCatid( $catdir) : mixed

标识获取id

Parameters

$catdir

Returns

mixed —