forked from Raindal/php_mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
32 lines (28 loc) · 868 Bytes
/
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
<?php
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 }();
}
// we're adding an entry for the new controller and its 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');
}
?>