This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
52 lines (48 loc) · 1.56 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
41
42
43
44
45
46
47
48
49
50
51
52
<?php
function call($controller, $action) {
// require the file that matches the controller name
require_once('controllers/' . $controller . '_controller.php');
// create a new instance of the needed controller
switch($controller) {
case 'about':
$controller = new AboutController();
break;
case 'act':
$controller = new ActController();
break;
case 'contacts':
$controller = new ContactsController();
break;
case 'historic':
$controller = new HistoricController();
break;
case 'marathon':
$controller = new MarathonController();
break;
case 'shows':
$controller = new ShowsController();
break;
}
// call the action
$controller->{ $action }();
}
// just a list of the controllers we have and their actions
// we consider those "allowed" values
$controllers = array('about' => ['index', 'error'],
'act' => ['index', 'show', 'error'],
'contacts' => ['index', 'error', 'error'],
'historic' => ['index', 'show', 'error'],
'marathon' => ['index', 'show', 'error'],
'shows' => ['index', 'error']);
// check that the requested controller and action are both allowed
// if someone tries to access something else he will be redirected to the error action of the pages controller
if (array_key_exists($controller, $controllers)) {
if (in_array($action, $controllers[$controller])) {
call($controller, $action);
} else {
call('shows', 'error');
}
} else {
call('shows', 'error');
}
?>