HELPER
Helper adalah
kumpulan fungsi yang diletakkan didalam folder system/helpers atau
applications/helpers. Biasanya helper sering dihunakan dalam view untuk
membantu proses yang berulang, seprti generate html, url, security, dan
lain-lain.
·
Penggunaan
Helper
Penggunaan
Helper terdapat 3 cara, yaitu:
1. .Didalam
file autoload.php
1
|
$autoload[‘helper’]
= array(‘form’);
|
2. Didalam
Constructor
1
2
3
4
5
6
7
|
Public
function__construct()
{
Parent::__construct();
$this->load->helper(‘form’);
}
|
3. Didalam
Fungsi
1
2
3
4
5
6
7
|
Public Function
index()
{
$this->load->helper(‘form’);
$this->load->view(‘login’);
}
|
- URL HELPER
- Form Helper
- · Form Helper (2)
- Form Helper (3)
· Flash Helper
syarat
1.
|
$autoload[‘libraries’]
= array (‘session’);
|
Controller
1
2
3
4
5
|
Public function index()
{
$this->session->set_flashdata(‘message’,’validasi
Login Berhasil!’);
$this->load->view(‘biodata’);
}
|
View
1.
|
If($this->session->flashdata(‘message’)){echo
$this->session-> flashdata(‘message’); }
|
B.
LIBRARIES
Libraries adalah
sekumpulan kelas dan fungsi yang dibuat untuk membantu pengembang aplikasi untuk dapat membangun aplikasi
dengan lebih cepat dan lebih efisien.
1.
|
$this->load->library(‘form_validation’);
|
Penggunaan
libraries terdapat 3 cara:
1.
Didalam
file aotoload.php
1.
|
$autoload[‘libraries’]
= array(‘form_validation’);
|
2.
Didalam
Constructor
1
2
3
4
5.
|
Public function_construct()
{
Parent::__construct();
$this->load->library(‘form_validation’);
}
|
3.
Didalam
Fungsi
1
2
3
4
5.
|
Public function index()
{
$this->load->helper(‘form’);
$this->load->library(‘form_validation’);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
Class Form extends CI_Controller {
Public function aksi(){
$this->load->library(‘form_validation’);
$this->form_validayion->set_rulers(‘email’,’Email’,’required
| valid_email’);
$this->form_validation->set_rules(‘password’,
‘Password’,’required | min_length[5] | max_length[12]’);
If
($this->form_validation->run() == FALSE)
$this->load->view(‘myform’);
else
$this->load->view(‘formsuccess’);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<html>
<head><title>Login
Form</title></head>
<body>
<?php echo
validation_errors(); ?>
<?php echo
form_open(‘form’);?>
<h5>Email
Address</h5>
<?php echo
form_input(‘email’);?>
<h5>Password</h5>
<?php echo
form_password(‘email’);?>
<?php echo
form_submit(‘submit’,’Login’);?>
<?php echo
form_close();?>
</body>
</html>
|
1
2
3
4
5
6
7
|
<html>
<head><little>My
Form</title></head>
<body>
<h3> You form was successfully submitted
</h3>
</body>
</html>
|
·
HELPER
TANGGAL INDONESIA
*sebelum
-Sekarang : 2015-06-04
v View
Sekarang
: <?php echo date(“Y-m-d”);?>
*Sesudah
-Sekarang : 04-06-2015
- Controller
$this->load->helper(‘tgl_indonesia’);
- View
Sekarang : <?php echo
tgl_indonesia(date(“Y-m-d”);?>
About the Author
0 komentar: