forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
executable file
·116 lines (75 loc) · 1.72 KB
/
function.php
File metadata and controls
executable file
·116 lines (75 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* 生成url
* string $route 路由
* array $param 参数
* boolean $scheme 是否展示完整url
*/
if (!function_exists('url')){
function url($route = '', $param = [], $scheme = false)
{
if(!$route){
return \yii\helpers\Url::current($param, $scheme);
}
$param[] = $route;
return \yii\helpers\Url::toRoute($param, $scheme);
}
}
/**
* 友好的打印调试
*/
if (!function_exists('dump'))
{
function dump()
{
if(func_num_args() < 1){
var_dump(null);
}
//获取参数列表
$args_list = func_get_args();
echo '<pre>';
foreach ($args_list as $arg) {
$type = gettype($arg);
if(!$arg){
var_dump($arg);
}elseif($type == 'array'){
print_r($arg);
}elseif(in_array($type, ['object', 'resource', 'boolean', 'NULL', 'unknown type'])){
var_dump($arg);
}else{
echo $arg . '<br>';
}
}
echo "</pre>";
}
}
/**
* 获取系统配置信息
*/
if (!function_exists('config')){
function config($name, $type='app')
{
$name = trim($name);
return \app\models\Config::findModel(['type' => $type])->getField($name);
}
}
/**
* 生成CSRF口令
*/
if (!function_exists('csrf_token')){
function csrf_token()
{
return Yii::$app->request->csrfToken;
}
}
/**
* 数组转对象
*/
if (!function_exists('array2object')){
function array2object($array) {
if(!is_array($array)){
return null;
}
return json_decode(json_encode($array, JSON_UNESCAPED_UNICODE));
}
}