-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
109 lines (79 loc) · 2.44 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
<?php
/*
* Kasyn Tang
* January 2024
* http://ktang.greenriverdev.com/328/diner/
* This is my Controller for the Diner app
*/
// Turn on error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Require the autoload file
require_once ('vendor/autoload.php');
require_once ('model/data-layer.php');
// Instantiate Fat-Free Framework (F3)
$f3 = Base::instance();
// Define a default route
$f3->route('GET /', function () {
// echo "My Diner";
// display a view page
$view = new Template();
echo $view->render('views/home.html');
});
// Define a breakfast route
$f3->route('GET /breakfast', function () {
echo "Breakfast";
// display a view page
$view = new Template();
echo $view->render('views/breakfast-menu.html');
});
// Define a order route
$f3->route('GET|POST /order1', function ($f3) {
// echo "order Form part 1";
//If the form has been posted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//Validate the data
$food = $_POST['food'];
$meal = $_POST['meal'];
//put the data in the session array
$f3->set('SESSION.food', $food);
$f3->set('SESSION.meal', $meal);
//redirect to order2 route
$f3->reroute('order2');
}
// get data from the model and add to the F3 "hive"
$f3->set('meals', getMeals());
// display a view page
$view = new Template();
echo $view->render('views/order-form-1.html');
});
// Define a order route
$f3->route('GET|POST /order2', function ($f3) {
// echo "order Form part 2";
//If the form has been posted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//Validate the data
$food = $_POST['food'];
$meal = $_POST['meal'];
//put the data in the session array
$f3->set('SESSION.food', $food);
$f3->set('SESSION.meal', $meal);
//redirect to order2 route
$f3->reroute('summary');
}
// add data to the F3 "hive"
$f3->set('condiments', getCondiments());
// display a view page
$view = new Template();
echo $view->render('views/order-form-2.html');
});
// Define a summary route
$f3->route('GET /summary', function () {
// echo "Breakfast";
// display a view page
$view = new Template();
echo $view->render('views/summary.html');
});
// Run Fat-Free
$f3->run();
//echo "My Diner";