codeigniter_test2/application/controllers/user_controller.php
2020-01-02 23:07:40 +07:00

62 lines
1.3 KiB
PHP

<?php
class User_controller extends CI_Controller{
function __Construct()
{
parent ::__construct();
$this->load->model('user_model');
}
function insert_user()
{
$data['judul'] = 'Insert Data User';
$this->load->view('user', $data);
}
function simpan_user()
{
$this->user_model->simpan_user();
$data['notifikasi'] = 'Data berhasil disimpan';
$data['judul']='Insert Data Berhasil';
}
function login()
{
$data['judul'] = 'Halaman Login';
$this->load->view('login', $data);
}
function validasi()
{
$user = $this->input->post('username');
$pass = $this->input->post('password');
$cek = $this->user_model->login($user,$pass);
//echo $cek;
if ($cek)
{
$session = array(
'username' => $user,
'isLoggedIn' => TRUE
);
$this->session->set_userdata($session);
redirect('barang_controller/barang');
echo $this->session->all_userdata();
}
else {
$this->load->view('login');
//echo 'salah';
}
}
function logout()
{
$array_items = array('username' => '', 'isLoggedin' => false);
$this->session->unset_userdata($array_items);
$this->session->sess_destroy();
//$session_destroy();
$data['judul'] = 'Halaman Login';
$this->load->view('login', $data);
}
}
?>