-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathpip.php
More file actions
65 lines (48 loc) · 1.79 KB
/
Copy pathpip.php
File metadata and controls
65 lines (48 loc) · 1.79 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
<?php
class pip {
private $controller;
private $action;
private $url;
function __construct(){
$segments = $this->startParams();
$segments = $this->startActions($segments);
$obj = new $this->controller;
die(call_user_func_array(array($obj, $this->action), array($segments)));
}
function startParams(){
global $config;
$this->controller = $config['default_controller'];
$this->action = 'index';
$this->url = APP_DIR;
$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
$script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
if($request_url != $script_url){
$this->url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/');
}
$segments = explode('/', $this->url);
if(isset($segments[0]) && $segments[0] != '') $this->controller = $segments[0];
if(isset($segments[1]) && $segments[1] != '') $this->action = $segments[1];
return $segments;
}
function startActions($segments){
global $config;
$path = APP_DIR . 'controllers' . DS . $this->controller . '.php';
$controller = $this->controller;
if(file_exists($path)){
require_once($path);
} else {
$segments[0] = "Controller '{$controller}' Not Found! ";
$this->controller = $config['error_controller'];
require_once(APP_DIR . 'controllers' . DS . $this->controller . '.php');
}
if(!method_exists($this->controller, $this->action)){
$this->action = 'index';
$action = $this->action;
$segments[0] = "Method '{$action}' in Controller '{$controller}' Not Found! ";
$this->controller = $config['error_controller'];
require_once(APP_DIR . 'controllers' . DS . $this->controller . '.php');
}
return $segments;
}
}
?>