1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!defined('BASEPATH')) { |
4
|
|
|
exit('No direct script access allowed'); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
class Admin_logs extends BaseAdminController |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public $per_page = 25; |
11
|
|
|
|
12
|
|
View Code Duplication |
public function __construct() { |
13
|
|
|
parent::__construct(); |
14
|
|
|
|
15
|
|
|
$this->load->library('DX_Auth'); |
16
|
|
|
admin_or_redirect(); |
17
|
|
|
|
18
|
|
|
$this->load->library('lib_admin'); |
19
|
|
|
$this->load->library('pagination'); |
20
|
|
|
$this->lib_admin->init_settings(); |
21
|
|
|
|
22
|
|
|
//cp_check_perm('logs_view'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function index($offset = 0) { |
26
|
|
|
$this->db->order_by('date', 'DESC'); |
27
|
|
|
$messages = $this->db->get('logs', (int) $this->per_page, (int) $offset); |
28
|
|
|
|
29
|
|
|
if ($messages->num_rows() > 0) { |
30
|
|
|
$messages = $messages->result_array(); |
31
|
|
|
} else { |
32
|
|
|
$messages = false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$total = $this->db->get('logs')->num_rows(); |
36
|
|
|
|
37
|
|
|
if ($total > $this->per_page) { |
38
|
|
|
$this->load->library('Pagination'); |
39
|
|
|
|
40
|
|
|
$config['base_url'] = site_url('admin/admin_logs/index'); |
|
|
|
|
41
|
|
|
$config['total_rows'] = $total; |
42
|
|
|
$config['per_page'] = $this->per_page; |
43
|
|
|
$config['uri_segment'] = $this->uri->total_segments(); |
44
|
|
|
|
45
|
|
|
$config['separate_controls'] = true; |
46
|
|
|
$config['full_tag_open'] = '<div class="pagination pull-left"><ul>'; |
47
|
|
|
$config['full_tag_close'] = '</ul></div>'; |
48
|
|
|
$config['controls_tag_open'] = '<div class="pagination pull-right"><ul>'; |
49
|
|
|
$config['controls_tag_close'] = '</ul></div>'; |
50
|
|
|
$config['next_link'] = lang('Next', 'admin') . ' >'; |
51
|
|
|
$config['prev_link'] = '< ' . lang('Prev', 'admin'); |
52
|
|
|
$config['last_link'] = lang('Last', 'admin') . ' ›'; |
53
|
|
|
$config['first_link'] = '‹ ' . lang('First', 'admin'); |
54
|
|
|
$config['cur_tag_open'] = '<li class="btn-primary active"><span>'; |
55
|
|
|
$config['cur_tag_close'] = '</span></li>'; |
56
|
|
|
$config['prev_tag_open'] = '<li>'; |
57
|
|
|
$config['prev_tag_close'] = '</li>'; |
58
|
|
|
$config['next_tag_open'] = '<li>'; |
59
|
|
|
$config['next_tag_close'] = '</li>'; |
60
|
|
|
$config['num_tag_close'] = '</li>'; |
61
|
|
|
$config['num_tag_open'] = '<li>'; |
62
|
|
|
$config['num_tag_close'] = '</li>'; |
63
|
|
|
$config['last_tag_open'] = '<li>'; |
64
|
|
|
$config['last_tag_close'] = '</li>'; |
65
|
|
|
$config['first_tag_open'] = '<li>'; |
66
|
|
|
$config['first_tag_close'] = '</li>'; |
67
|
|
|
|
68
|
|
|
$this->pagination->num_links = 5; |
69
|
|
|
$this->pagination->initialize($config); |
70
|
|
|
//$this->template->assign('paginator', $this->pagination->create_links_ajax()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->template->add_array( |
74
|
|
|
[ |
75
|
|
|
'messages' => $messages, |
76
|
|
|
// 'languages' => ShopCore::$ci->cms_admin->get_langs(true), |
77
|
|
|
'paginator' => $this->pagination->create_links_ajax(), |
78
|
|
|
] |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->template->show('logs', false); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.