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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index() { /** * Pass data to views * 1. Option one * $data['anything'] = 'You can put data here'; * $this->load->view('main/home', $data); * * 2. Option two * $anything = 'You can put data here'; * $this->load->vars('anything', $anything); * * Example:https://codeigniter.com/userguide3/tutorial/news_section.html * Ref:https://codeigniter.com/userguide3/libraries/loader.html#CI_Loader::vars * */
$data['anything'] = 'You can put data here';
$site_info = Site_info_model::first();
$this->load->vars('lang', get_lang()); $this->load->vars('site_info', $site_info); // same with $data['site_info'], you can call $site_info on views/main/home.php
$this->load->view('main/home', $data); //on application/views/main/home.php, you can call $anything. }
public function send_email() { /** * Email Class * Ref:https://codeigniter.com/userguide3/libraries/email.html * */
$this->load->config('email');
$from = 'from@email.com'; $from_name = 'from'; $to = 'to@email.com'; $subject = 'Title'; $message = 'This is content'; $result = ci_send_email($from, $from_name, $to, $subject, $message);
if ($result) { echo "Success"; } else { echo "Failed"; } }
public function pagination_demo($page = 1) { /** * Pagination Class * Ref:https://www.codeigniter.com/userguide3/libraries/pagination.html * */ $per_page = 2; //how many items you want to show for each page
$query = News_model::where('deleted', 0); $count = $query->count(); $news = $query->take($per_page)->skip($per_page * ($page - 1))->get(); $this->load->vars('news', $news);
$this->load->library('pagination');
$config['base_url'] = front_url('home/pagination_demo/'); //pagination url $config['total_rows'] = $count; $config['per_page'] = $per_page; $config['use_page_numbers'] = true; /* This Application Must Be Used With BootStrap 3 * */ $config['full_tag_open'] = "<ul class='pagination'>"; $config['full_tag_close'] = "</ul>"; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_tag_open'] = "<li>"; $config['next_tagl_close'] = "</li>"; $config['prev_tag_open'] = "<li>"; $config['prev_tagl_close'] = "</li>"; $config['first_tag_open'] = "<li>"; $config['first_tagl_close'] = "</li>"; $config['last_tag_open'] = "<li>"; $config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$page_links = $this->pagination->create_links(); $this->load->vars('page_links', $page_links); $this->load->view('main/news'); }
public function ci_database($page = 1) { /** * Query Builder Class * Ref:https://codeigniter.com/userguide3/database/query_builder.html * */ $per_page = 2; //how many items you want to show for each page
$count = $this->db->where('deleted', 0)->get('news')->num_rows(); $news = $this->db->where('deleted', 0)->get('news', $per_page, $per_page * ($page - 1))->result(); $this->load->vars('news', $news);
$this->load->library('pagination');
$config['base_url'] = front_url('home/ci_database/'); //pagination url $config['total_rows'] = $count; $config['per_page'] = $per_page; $config['use_page_numbers'] = true; /* This Application Must Be Used With BootStrap 3 * */ $config['full_tag_open'] = "<ul class='pagination'>"; $config['full_tag_close'] = "</ul>"; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_tag_open'] = "<li>"; $config['next_tagl_close'] = "</li>"; $config['prev_tag_open'] = "<li>"; $config['prev_tagl_close'] = "</li>"; $config['first_tag_open'] = "<li>"; $config['first_tagl_close'] = "</li>"; $config['last_tag_open'] = "<li>"; $config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$page_links = $this->pagination->create_links(); $this->load->vars('page_links', $page_links); $this->load->view('main/news'); }
public function captcha($action = '') { /** CAPTCHA Helper * Ref: https://www.codeigniter.com/userguide3/helpers/captcha_helper.html * Directory of assets/captcha must be exist * */
if ($action == 'check') { $this->form_validation->set_rules('captcha_code', 'Captcha code', 'trim|required'); if ($this->form_validation->run() == false) { echo validation_errors(); } elseif (captcha_checking()) { echo "Correct!"; } else { //$this->session->flashdata('error_msg');//default error message echo "Failed!"; } }
$captcha = captcha_img(); echo $captcha; echo form_open(front_url('home/captcha/check')); echo form_input(array( 'type' => 'text', 'name' => 'captcha_code', 'class' => 'form-control', )); echo form_button(array( 'type' => 'submit', 'content' => 'Verify', 'class' => 'btn btn-primary', )); echo form_close(); }
public function testing() { $this->load->view('webadmin/invoice_export'); }
public function phpinfo() { phpinfo(); }
}
|