• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to transfer data between model & controller?

#1
[eluser]imanhunter[/eluser]
Hi,

I'm struggling to learn how to transfer data between model & controller. Yes, I'm new to both PHP & CI so you can call me NoOb. Have learn through tutorial (vids/article) but still can't get the idea.

Below is my code

Model
Code:
function sahDaftarmasuk($alnamapengguna, $alkatalaluan)
    {
        $this->db->where('namapengguna',$alnamapengguna);
        $this->db->where('katalaluan',$alkatalaluan);
        $this->db->where('keaktifan','1');
        $dapatmaklumat = $this->db->get('spkppi_pengguna');
        
        if($dapatmaklumat->num_rows() > 0)
        {
            $maklumatpengguna = array();
            $maklumatpengguna = $dapatmaklumat->row_array();
            return $maklumatpengguna;
        }
        else
        {
            $this->load->view('vsyslogin');;
        }
    }


here is the controller

Code:
function daftarmasuk()
    {
        $this->form_validation->set_rules('namapengguna', 'Nama Pengguna', 'required|trim|max_length[100]|xss_clean');
        $this->form_validation->set_rules('katalaluan', 'Kata Laluan', 'required|trim|min_length[6]|max_length[20]|xss_clean');
        
        if ($this->form_validation->run() === FALSE)
        {
            $data['pagetitle'] = "maklumat sekolah";
            $this->load->vars($data);
            $this->load->view('vsyslogin');
        }
        else
        {
            $this->load->Model('Msyslogin');
            
            $maklumatpengguna = array();

            $alnamapengguna = $this->input->post('namapengguna');
            $alkatalaluan = do_hash(do_hash($this->input->post('katalaluan')),'md5');
            
            $this->Msyslogin->sahDaftarmasuk($alnamapengguna, $alkatalaluan);
            
            if($maklumatpengguna['kelayakkan'] == 0)
            {
                $data['kelayakkan'] = $maklumatpengguna['kelayakkan'];
                $this->load->view('admin/avdashboard', $data);
            }
            else if ($maklumatpengguna['kelayakkan'] == 1)
            {
                $this->load->view('pkelas/pjdashboard');
            }
            else if ($maklumatpengguna['kelayakkan'] == 2)
            {
                $this->load->view('psyarikat/psdashboard');
            }
            else
            {
                redirect('vsyslogin');
            }
        }    
    }

The idea here is if the user log into the app, then it will get the user data (namapengguna & katalaluan) from db which after that it will also get the user rank. different rank will redirect user to different dashboard.

I'm trying to get the row into an array which will return to controller then will be extracted in it.


Messages In This Thread
How to transfer data between model & controller? - by El Forum - 03-19-2011, 03:59 AM
How to transfer data between model & controller? - by El Forum - 03-19-2011, 04:09 AM
How to transfer data between model & controller? - by El Forum - 03-19-2011, 04:34 AM
How to transfer data between model & controller? - by El Forum - 03-19-2011, 04:44 AM
How to transfer data between model & controller? - by El Forum - 03-19-2011, 10:45 AM
How to transfer data between model & controller? - by El Forum - 03-19-2011, 10:56 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.