-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
141 lines (120 loc) · 2.67 KB
/
functions.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Created by PhpStorm.
* User: Code刘
* Date: 2018/12/3
* Time: 17:23
*/
/**
* 自动加载函数
* @param $s
*/
function autoloads($s)
{
$path = explode('\\',$s);
$c = $path[1];
if (isset($c))
{
switch ($c)
{
case 'con':
$c = 'controller';
break;
case 'mod':
$c = 'module';
break;
case 'vi':
$c = 'view';
break;
}
$path[1] = $c;
$path = implode('/',$path);
}else{
$path = $path[0];
}
$a = './app/'.$path.'.php';
if (file_exists($a))
{
include_once $a;
}else{
throw new Exception("找不到{$a}类!");
}
}
/**
* 入口方法
* @throws Exception
*/
function go_index()
{
global $tiem_index,$con_index,$fun_index;
$path = explode('/',PATH_INFO);
$p1 = $path[1] ?: $tiem_index;
$p2 = $path[2] ?: $con_index;
$p3 = $path[3] ?: $fun_index;
define('TIEM',$p1);
define('CON' ,$p2);
define('FUN' ,$p3);
if (is_dir(ROOT.'/app/'.$p1))
{
$c = $p1.'\\con\\'.$p2;
$f = $p3;
$con = new $c();
if (method_exists($con,$f))
{
open_redis();//开启redis
if (method_exists($con,'_initialize'))
{
$con->_initialize();//初始化默认执行
}
echo $con->$f();//执行动作
}else{
throw new Exception("找不到{$con}类的{$f}方法!");
}
}else{
throw new Exception("找不到{$p1}端!");
}
}
/**
* 开启redis
* 存储在$GLOBALS['redis']
*/
function open_redis()
{
global $redis,$redis_ip,$redis_port;
if (!($redis instanceof Redis))
{
$redis = new Redis();
$redis->pconnect($redis_ip, $redis_port, 0);
$GLOBALS['redis'] = $redis;
}
}
/**
* 重定向
* @param $url
* @param $start
*/
function headers($url,$start = false)
{
global $view_replace;
if ($start === true)
{
$url = $view_replace['__ROOT__'].$url;
}
header('Location: '.$url);
}
/**
* 公共AJAX返回格式
* @param $code 返回码
* @param $data 返回数据
* @param string $url 返回后跳转到URL(跳转动作由前端完成)
* @return string
*/
function ajax_return($code,$data,$url = '')
{
$arr = array(
'code' => $code,
'data' => $data,
'url' => $url
);
return json_encode($arr,JSON_UNESCAPED_UNICODE);
}