Membuat session dari 2 (dua) tabel berbeda di codeigniter

Permisi master, saya mau tanyain cara menyimpan session di codeigniter, sessionnya dari 2 (dua) buah tabel yang berbeda..

Saat form login, selain mengecek username dan password dari tabel user, juga ada select option untuk memilih nama perusahaan.. saya sudah berhasil menyimpan session dari tabel user, tapi dari tabel perusahaan sy membutuhkan 2 buah field yg dijadikan session, yakni id_pt dan nama_pt.. untuk field id_pt sendiri sudah berhasil sy simpan, tapi sy kesulitan menyimpan session untuk nama_pt.

berikut controllernya :


public function index()
  {
    $data['title'] = 'Login';
    $data['perusahaan'] = $this->db->query("SELECT id_pt, nama_pt FROM perusahaan");
    $this->load->view('login',$data);
  }


public function auth()
{
	if (isset($_POST) && !empty($_POST)) {
            $this->form_validation->set_rules('user', 'Username', 'trim|required');
            $this->form_validation->set_rules('password', 'Password', 'trim|required');
            $this->form_validation->set_rules('id_pt', 'Perusahaan', 'trim|required');

            if ($this->form_validation->run() == FALSE){
                $this->session->set_flashdata("msg","
                        <div class='alert alert-warning fade in'>
                            <a href='#' class='close' data-dismiss='alert'>×</a>
                            <strong>Gagal !</strong> Username dan Password Harus Diisi !
                        </div>");
                header('location:'.base_url().'Log');
            }else{
            	$usr = $this->input->post('user');
            	$pw = $this->input->post('password');
            	$id_pt = $this->input->post('id_pt');
            	$pww = md5($pw);

            	$q_cek_login = $this->db->get_where('users', array('username' => $usr));
            	$q_cek_sales = $this->db->get_where('tb_sales', array('email' => $usr));
		if(count($q_cek_login->result())>0)
		 {
		   foreach($q_cek_login->result() as $qck)
			{
			$pass=$qck->password;
			if($qck->username==$usr && $pass==$pww)
		   	 {
			if ($qck->level=='Gudang') {
			$qcek = $this->db->get_where('users', array('username' => $usr ));
			foreach ($qcek->result() as $sess) {
			$sess_data['logged_in'] = 'gudang ok';
			$sess_data['username'] = $sess->username;
			$sess_data['nama'] = $sess->nama;
			$sess_data['level'] = $sess->level;
			$sess_data['id_pt'] = $id_pt;
			$this->session->set_userdata($sess_data);
			}
			header('location:'.site_url('Dashboard'));
			}
			else if($qck->level=='Pimpinan') {
			$qcek = $this->db->get_where('users', array('username' => $usr ));
			 foreach ($qcek->result() as $sess) {
				$sess_data['logged_in'] = 'pimpinan ok';
				$sess_data['username'] = $sess->username;
				$sess_data['nama'] = $sess->nama;
				$sess_data['level'] = $sess->level;
				$sess_data['id_pt'] = $id_pt;
				$this->session->set_userdata($sess_data);
				}
				header('location:'.site_url('Dashboard'));
				}
				else
			{
			$this->session->set_flashdata("msg","
			<div class='alert alert-warning fade in'>
			<a href='#' class='close' data-dismiss='alert'>×</a>
			<strong>Failed!</strong> Username atau Password Salah !
			</div>");
			header('location:'.site_url('Log'));
			}
		          }else
			{
			$this->session->set_flashdata("msg","
			<div class='alert alert-warning fade in'>
			<a href='#' class='close' data-dismiss='alert'>×</a>
			<strong>Failed!</strong> Username atau Password Salah !
			</div>");
			header('location:'.base_url('Log'));
			}
			}
			}
			else
			{
			$this->session->set_flashdata("msg","
			<div class='alert alert-warning fade in'>
			<a href='#' class='close' data-dismiss='alert'>×</a>
			<strong>Failed!</strong> Username yang anda gunakan salah !
			</div>");
			header('location:'.base_url().'Log');
			}
            }
        }else{
        	$this->error();
        }
	}

saya kesulitan untuk mengambil session nama_pt, untuk id_pt sudah bisa dengan cara mengambil nilai input pada form.

Mohon masukannya, thanks.

avatar miamiu
@miamiu

25 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban