-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
81 lines (48 loc) · 1.54 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
<?php
require realpath("vendor/autoload.php");
use App\Base\Request\Request;
use App\Base\Route\Route;
use App\Controller\ProductsController;
$route = new Route();
// route to main page
$route->get('/', function ($request) {
return (new ProductsController($request))->get_front();
});
// route to add product page
$route->get('/add-product', function ($request) {
return (new ProductsController($request))->get_add_product();
});
// route to delete products
$route->post('/', function (Request $request) {
$controller = new ProductsController($request);
if ($request->get('_method') == 'delete') {
return $controller->delete();
}
return $controller->get_front();
});
// route to store product
$route->post('/', function (Request $request) {
return (new ProductsController($request))->store();
});
// if ($_SERVER['REQUEST_URI'] == "/") {
// if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// # code...
// echo new ProductsController();
// }
// if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// if ($_POST['_method'] == 'delete') {
// # code...
// echo (new ProductsController())->delete();
// }
// }
// }
// if ($_SERVER['REQUEST_URI'] == "/products") {
// if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// # code...
// echo (new ProductsController())->get_add_product();
// }
// if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// # code...
// echo (new ProductsController())->store();
// }
// }