-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.php
48 lines (31 loc) · 830 Bytes
/
site.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
<?php
use Hcode\Model\Category;
use Hcode\Model\Product;
use Hcode\Page;
$app->get('/', function() {
$products = Product::listAll();
$page = new Page();
$page->setTpl("index", [
'products' => Product::checkList($products)
]);
});
$app->get('/categories/:idcategory', function($idcategory){
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$category = new Category();
$category->get((int)$idcategory);
$pagination = $category->getProductsPage($page);
$pages = [];
for ($i=1; $i < $pagination['pages']; $i++) {
array_push($pages, [
'link' => '/categories/' . $category->getidcategory() . '?page=' . $i,
'page' => $i
]);
}
$page = new Page();
$page->setTpl('category', [
'category' => $category->getValues(),
'products' => $pagination['data'],
'pages' => $pages
]);
});
?>