Welcome Guest, Not a member yet? Register   Sign In
How to transfer data between model & controller?
#2

[eluser]WanWizard[/eluser]
You shouldn't load views in your model. Model methods are strictly behind the scenes blocks of code.

Instead, do
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
        {
            return FALSE;
        }
    }

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');
            
            $maklumatpengguna = $this->Msyslogin->sahDaftarmasuk($alnamapengguna, $alkatalaluan);
            
            if($maklumatpengguna === FALSE)
            {
                redirect('vsyslogin');
            }
            elseif($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');
            }
        }    
    }

So have your model methods return the values they are supposed to retrieve, or FALSE is there is an error. Check the return value in the controller, and base your descisions on that value. Your controller should contain the application flow logic, not the model.


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



Theme © iAndrew 2016 - Forum software by © MyBB