11-05-2014, 09:39 AM
(This post was last modified: 11-05-2014, 10:33 AM by bobykurniawan.)
Hello from indonesia. I try to make my own library (Haha i don't if it is right or not). Okey first, i'll put the code's
The code is working fine, but my real problems are :
1. What is the function of library ?
2. Is my library right ?
3. If right, what the different with models ?
Sory, for my bad english.
PHP Code:
class Donaturlib {
function is_admin()
{
$ci =&get_instance();
$cek = $ci->donaturlib->security();
if($cek != null)
{
foreach ($cek as $key) {
$username = $key->username;
}
$hasil = $ci->donaturlib->getPeople($username);
foreach ($hasil as $levelnya ) {
$lv = $levelnya->level;
}
if ($lv != 1) {
return false;
}
else
{
return true;
}
}else{
$msg="<div class='alert alert-danger alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert'>
<span aria-hidden='true'>×</span><span class='sr-only'>Close</span></button>
<strong>Harap login terlebih dahulu
</div>";
$ci->session->set_flashdata('donatur',$msg);
redirect('welcome','refresh');
}
}
function getPeople($username)
{
$ci =&get_instance();
$query = $ci->db->query("select level from user where username ='$username'");
return $query->result();
}
function checkexist($namadonasi,$tabel1)
{
$ci = &get_instance();
$fieldpilih ='*';
$hasil = $ci->modeldonatur->pilihdata($tabel1,$namadonasi,$fieldpilih);
if($hasil!=null)
{
return true;
}
else
{
return false;
}
}
function security()
{
$ci =&get_instance();
$vCuser = $ci->input->cookie('dnt_user');
$vCsesi = $ci->input->cookie('dnt_sesi');
$tbl='logindata';
$fieldpilih='*';
$fieldkondisi=array('username'=>$vCuser,'sesi'=>$vCsesi);
$hasil = $ci->modeldonatur->pilihdata($tbl,$fieldkondisi,$fieldpilih);
if($hasil!=null)
{
//simpan ke cookie
$vCookie1['name'] = 'ik_inv_ck_user';
$vCookie1['value'] = $vCuser;
$vCookie1['expire'] = '600';
$ci->input->set_cookie($vCookie1);
//simpan ke cookie token/sesi
$vCookie2['name'] = 'ik_inv_ck_sesi';
$vCookie2['value'] = $vCsesi;
$vCookie2['expire'] = '600';
$ci->input->set_cookie($vCookie2);
}
return $hasil;
}
}
The code is working fine, but my real problems are :
1. What is the function of library ?
2. Is my library right ?
3. If right, what the different with models ?
Sory, for my bad english.