|
25 | 25 | if ($uri == '/') { |
26 | 26 | $response = ['response' => 'No content to show']; |
27 | 27 | echo json_encode($response); |
28 | | -} else { |
29 | | - $src = explode('/', $uri); |
30 | | - $model = ucfirst($src[1]); |
31 | | - $controller = $model.'Controller'; |
32 | | - $method = (isset($src[2])) ? $src[2] : 'index'; |
33 | | - |
34 | | - if (isset($src[3]) && empty($the_request)) { |
35 | | - $the_request = filter_var($src[3], FILTER_SANITIZE_STRING); |
36 | | - } |
| 28 | + exit; |
| 29 | +} |
37 | 30 |
|
38 | | - /* |
39 | | - * AppModel file |
40 | | - */ |
41 | | - $app_model = APP . 'model' . DS .'AppModel.php'; |
| 31 | +$src = explode('/', $uri); |
| 32 | +$model = ucfirst($src[1]); |
| 33 | +$controller = $model.'Controller'; |
| 34 | +$method = (isset($src[2])) ? $src[2] : 'index'; |
42 | 35 |
|
43 | | - if (file_exists($app_model)) { |
44 | | - require_once $app_model; |
45 | | - } |
46 | | - /* |
47 | | - * require files of current Model/Controller |
48 | | - */ |
49 | | - $model_file = APP . 'model ' . DS . $model.'.php'; |
50 | | - |
51 | | - if (file_exists($model_file)) { |
52 | | - require_once $model_file; |
53 | | - } |
54 | | - /* |
55 | | - * call current class/method |
56 | | - */ |
57 | | - $controller_file = APP . 'controller' . DS . $controller.'.php'; |
| 36 | +if (isset($src[3]) && empty($the_request)) { |
| 37 | + $the_request = filter_var($src[3], FILTER_SANITIZE_STRING); |
| 38 | +} |
58 | 39 |
|
59 | | - if (file_exists($controller_file)) { |
| 40 | +/* |
| 41 | +* AppModel file |
| 42 | +*/ |
| 43 | +$app_model = APP . 'model' . DS .'AppModel.php'; |
60 | 44 |
|
61 | | - require $controller_file; |
| 45 | +if (file_exists($app_model)) { |
| 46 | + require_once $app_model; |
| 47 | +} |
| 48 | +/* |
| 49 | +* require files of current Model/Controller |
| 50 | +*/ |
| 51 | +$model_file = APP . 'model ' . DS . $model.'.php'; |
62 | 52 |
|
63 | | - $load_class = 'SimpleORM\app\controller\\' . $controller; |
64 | | - $class = new $load_class(); |
65 | | - $set = $class->$method($the_request); |
| 53 | +if (file_exists($model_file)) { |
| 54 | + require_once $model_file; |
| 55 | +} |
| 56 | +/* |
| 57 | +* call current class/method |
| 58 | +*/ |
| 59 | +$controller_file = APP . 'controller' . DS . $controller.'.php'; |
66 | 60 |
|
67 | | - } else { |
68 | | - throw new Exception('Controller '.$controller.' Not Found'); |
69 | | - } |
| 61 | +if (!file_exists($controller_file)) { |
| 62 | + throw new Exception('Controller '.$controller.' Not Found'); |
| 63 | +} |
70 | 64 |
|
71 | | - /* |
72 | | - * Declare all variables if passed in return |
73 | | - */ |
74 | | - if (!empty($set) && is_array($set)) { |
75 | | - foreach ($set as $k => $v) { |
76 | | - ${$k} = $v; |
77 | | - } |
| 65 | +require $controller_file; |
| 66 | +$load_class = 'SimpleORM\app\controller\\' . $controller; |
| 67 | +$class = new $load_class(); |
| 68 | +$set = $class->$method($the_request); |
| 69 | + |
| 70 | +/* |
| 71 | +* Declare all variables if passed in return |
| 72 | +*/ |
| 73 | +if (!empty($set) && is_array($set)) { |
| 74 | + foreach ($set as $k => $v) { |
| 75 | + ${$k} = $v; |
78 | 76 | } |
| 77 | +} |
79 | 78 |
|
80 | | - /* |
81 | | - * If method has a view file, include |
82 | | - */ |
83 | | - $view_file = __DIR__ . DS . 'app' . DS . 'view' . DS . $model . DS . $method .'.php'; |
| 79 | +/* |
| 80 | +* If method has a view file, include |
| 81 | +*/ |
| 82 | +$view_file = __DIR__ . DS . 'app' . DS . 'view' . DS . $model . DS . $method .'.php'; |
84 | 83 |
|
85 | | - if (file_exists($view_file)) { |
86 | | - include $view_file; |
87 | | - } |
| 84 | +if (file_exists($view_file)) { |
| 85 | + include $view_file; |
88 | 86 | } |
0 commit comments