-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
63 lines (47 loc) · 1.31 KB
/
index.php
File metadata and controls
63 lines (47 loc) · 1.31 KB
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
<?php
session_start();
require 'config/dev.php';
require 'helpers.php';
require 'router.php';
switch ($_GET['route']) {
case 'customers':
view('customers/index', [
'customers' => []
]);
break;
case 'orders':
view('orders/index', [
'orders' => []
]);
break;
case 'products':
require 'src/Repositories/ProductsRepository.php';
$repo = new ProductsRepository();
view('products/index', [
'products' => $repo->all()
]);
break;
case 'products/add':
require 'src/Repositories/ProductsRepository.php';
$repo = new ProductsRepository();
$product = new Product();
$product->setName('LCD 24 pulgadas');
$product->setStock(20);
$product->setPrice(899);
$product->setBrand('Phillips');
$product->setCategoryId(7);
$product->setPhoto('no-image.jpg');
$id = $repo->add($product);
if (is_int($id)) {
$_SESSION['flash'] = 'El producto ha sido guardado!';
header('location: route=products');
}
view('products/add', [
'product' => $_POST['product'] ?? []
]);
break;
case 'products/view':
break;
default :
view('index');
}