-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
40 lines (34 loc) · 1.03 KB
/
routes.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
<?php
/**
* Call; get the controller required
* @param [string] $controller [the nam eof the controller to load]
* @param [string] $action [the name of the method inside that controller to trigger]
*/
function call($controller, $action) {
require_once('controllers/' . $controller . 'Controller.php');
switch($controller) {
case 'pages':
$controller = new PagesController();
break;
case 'posts':
// we need the model to query the database later in the controller
require_once( 'models/Post.php');
$controller = new PostsController();
break;
}
$controller->{ $action }();
}
// adding entry for - new controller + actions
$controllers = array(
'pages' => ['home', 'error'],
'posts' => ['index', 'show']);
if (array_key_exists($controller, $controllers)) {
if (in_array($action, $controllers[$controller])) {
call($controller, $action);
} else {
call('pages', 'error');
}
} else {
call('pages', 'error');
}
?>