-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
111 lines (72 loc) · 2.22 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/*
* Authors: George McMullen, Shawn Potter
*/
//turn on error reporting
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);
//require autoload file
require_once("vendor/autoload.php");
require $_SERVER['DOCUMENT_ROOT'].'/../ht-db-config.php';
//start a session
session_start();
//create an instance of the base class
$f3 = Base::instance();
//instanitate classes
$controller = new Controller($f3, $dbh);
$register = new Register($dbh, $f3);
$login = new Login($dbh, $f3);
$validator = new Validator();
$community = new Community($dbh, $f3);
$data = new DataLayer($dbh, $f3);
$logout = new Logout($f3);
// set fat-free debugging
$f3->set('DEBUG', 3);
// define a default route (home page)
$f3->route('GET /', function($f3){
global $controller;
$controller->home();
});
// define route to login page
$f3->route('GET|POST /login', function(){
global $controller;
$controller->login();
});
// define route to register page
$f3->route('GET|POST /register', function(){
global $controller;
$controller->register();
});
// define a dynamic route to each community page
$f3->route('GET /community/@communityID', function($f3){
global $controller;
$communityID = $f3->get("PARAMS.communityID");
if($communityID <= 0 || $communityID >= 10){
$f3->reroute("/");
}
$controller->community($communityID);
});
// define a dynamic route to each page for posts
$f3->route('GET|POST /community/@communityID/@postID', function($f3){
global $controller;
$communityID = $f3->get("PARAMS.communityID");
$postID = $f3->get("PARAMS.postID");
if($communityID <= 0 || $communityID >= 10){
$f3->reroute("/");
}
$controller->posts($communityID, $postID);
});
// Submit page with function
$f3->route('GET|POST /community/@communityID/submit', function($f3){
global $controller;
$communityID = $f3->get("PARAMS.communityID");
$controller->submit($communityID);
});
// Logout page with function
$f3->route('GET /logout', function($f3){
global $logout;
$logout->logout($f3);
});
//run fat free
$f3->run();