/
product.php
59 lines (49 loc) · 1.74 KB
/
product.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
<?php
use Fuel\Core\View;
/**
* The Home Controller
*
* @package app
* @extends Controller
*/
class Controller_Product extends Controller_Base_Core
{
public function before()
{
parent::before();
}
public function after($response)
{
$response = parent::after($response);
return $response;
}
public function action_index()
{
$this->data['product'] = Model_Base_Product::get_by(array(
'where' => array(array('status', '=', 1))
));
$total_product = Model_Base_Product::count_by(array(
'where' => array(array('status', '=', 1))
));
View::set_global('total_page', ceil($total_product / _DEFAULT_LIMIT_));
$this->template->title = 'Product List';
$this->template->content = View::forge($this->layout . '/product/list', $this->data);
}
public function action_detail($code = null)
{
$this->data['product'] = Model_Base_Product::get_by_code($code, array(
'where' => array(array('status', '=', 1))
));
if (empty($this->data['product']['id'])) {
Response::redirect('/');
}
$this->data['product']['sub_photo'] = Model_Base_Product::get_sub_photo($this->data['product']['id']);
$category_ids = Model_Base_ProductCategory::get_by('category_id', 'product_id', $this->data['product']['id']);
if (!empty($category_ids)) {
$this->data['products'] = Model_Base_Product::get_by_category_ids($category_ids, 0, 5);
}
View::set_global('product', $this->data['product']);
$this->template->title = 'Product List';
$this->template->content = View::forge($this->layout . '/product/detail', $this->data);
}
}